diff --git a/app.py b/app.py index 5ceaca6..e2d83ac 100644 --- a/app.py +++ b/app.py @@ -386,7 +386,7 @@ def index(): Returns: str: The rendered HTML content for the index page. """ - return render_template('index.html') + return render_template('index.html', gateway_ips=gateway_ips) @app.route('/analysis') def analysis(): @@ -727,21 +727,22 @@ def set_gateways(): """ global gateway_ips data = request.form - for key in [f'gateway{i}' for i in range(1, 11)]: + + # Create an ordered dictionary of gateways + ordered_gateways = {} + for i in range(1, 11): + key = f'gateway{i}' input_ip = data.get(key, '').strip() - if input_ip: - try: - ipaddress.ip_address(input_ip) - gateway_ips[key] = input_ip - except ValueError: - return jsonify({"error": f"Invalid IP address provided for {key}"}), 400 + ordered_gateways[key] = input_ip + + # Update the global gateway_ips with ordered data + gateway_ips.update(ordered_gateways) for gateway, ip_address in gateway_ips.items(): print(f"Gateway {gateway} has IP address: {ip_address}") return jsonify({"message": "Gateway IPs updated successfully"}), 200 - @app.route('/get_gateways', methods=['GET']) def get_gateways(): return jsonify(gateway_ips) diff --git a/templates/index.html b/templates/index.html index 0481b8b..d712c8e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -682,189 +682,192 @@

-
-

Configure LoRaWAN Gateways

-
-

- The Configure LoRaWAN Gateway section allows you to set up to ten Dragino LPS8N LoRaWAN gateways. -

- -

Empty values will be ignored, and the Gateway IP address will remain unchanged

-
-
-
- -
-
- - + + + + async init() { + await this.loadGatewayIPs(); // Load IPs first + this.createGatewayInputs(); // Then create inputs with loaded values + this.setupEventListeners(); + await this.checkAllGateways(); // Check gateway statuses + } + + } + + // Initialize the gateway manager + document.addEventListener('DOMContentLoaded', () => { + new GatewayManager(); + }); + +