Upload files to "/"
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask import Flask, jsonify
|
||||
from flask_cors import CORS
|
||||
from subprocess import run, PIPE
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
# List of IP addresses to check
|
||||
devices = {
|
||||
'pi4': '{IP}',
|
||||
'pi5': '{IP}',
|
||||
'pi0': '{IP}'
|
||||
}
|
||||
|
||||
def is_device_connected(ip_address):
|
||||
result = run(['ping', '-c', '1', ip_address], stdout=PIPE, stderr=PIPE, tex>
|
||||
return result.returncode == 0
|
||||
|
||||
@app.route('/check_status/<device>')
|
||||
def check_status(device):
|
||||
ip_address = devices.get(device)
|
||||
if ip_address:
|
||||
status = 'online' if is_device_connected(ip_address) else 'offline'
|
||||
return jsonify({'status': status})
|
||||
else:
|
||||
return jsonify({'error': 'Device not found'}), 404
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
Reference in New Issue
Block a user