#!/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/') 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)