diff --git a/README.md b/README.md index 7e96ff9..5db4846 100644 --- a/README.md +++ b/README.md @@ -71,12 +71,13 @@ From the configuration page, you can connect to a LoRa transmitter to start send The 'Configure LoRaWAN Gateway' section allows you to set up to ten Dragino LPS8N LoRaWAN gateways. -- Click the "Configure Gateway" button to start configuring each gateway's IP address. -- Skip configuring a gateway or disconnect an existing one by leaving the input field empty. +- Click the "Update Gateways" button to update each gateway's IP address. +- Skip configuring a gateway by leaving the input field empty. - All entered IP addresses are validated for correct formatting. - Once configured, the application automatically retrieves and stores LoRaWAN traffic from each active gateway. - Access and analyze stored traffic in 'survey mode'. + ![gateways](./doc/img/gateways.png) ## Analysis Mode diff --git a/app.py b/app.py index 2dcde53..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,20 +727,25 @@ 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) @app.route('/downloadPackets', methods=['GET']) def downloadPackets(): diff --git a/doc/img/gateways.png b/doc/img/gateways.png index e32ca57..0e2c332 100644 Binary files a/doc/img/gateways.png and b/doc/img/gateways.png differ diff --git a/templates/index.html b/templates/index.html index 1653ebf..d712c8e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -202,7 +202,7 @@ }) .catch(error => { console.error('Error:', error); - Swal.fire('Oops!', 'Something went wrong. The port might already be in use.', 'error'); + Swal.fire('Oops!', 'Something went wrong.', 'error'); }); } }); @@ -398,7 +398,7 @@ }) .catch(error => { console.error('Error:', error); - Swal.fire('Oops!', 'Something went wrong. The port might already be in use.', 'error'); + Swal.fire('Oops!', 'Something went wrong.', 'error'); }); } }); @@ -594,7 +594,7 @@ }) .catch(error => { console.error('Error:', error); - Swal.fire('Oops!', 'Something went wrong. The port might already be in use.', 'error'); + Swal.fire('Oops!', 'Something went wrong.', 'error'); }); } }); @@ -682,75 +682,234 @@

-
-

Configure LoRaWAN Gateways

+
+

Configure LoRaWAN Gateways

+

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

    -
  • Click the "Configure Gateway" button to start configuring each gateway's IP address.
  • -
  • Skip configuring a gateway or disconnect an existing one by leaving the input field empty.
  • +
  • Enter the IP address for each gateway you want to configure.
  • +
  • Leave the input field empty to keep the current IP or disconnect an existing one.
  • All entered IP addresses are validated for correct formatting.
  • Once configured, the application automatically retrieves and stores LoRaWAN traffic from each active gateway.
  • Access and analyze stored traffic in 'survey mode'.
+

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

-
- +
+
+ +
+
- + } + async loadGatewayIPs() { + try { + const response = await fetch('/get_gateways'); + if (!response.ok) throw new Error('Failed to fetch gateway IPs'); + + const data = await response.json(); + this.gatewayIPs = data; + } catch (error) { + console.error('Error loading gateway IPs:', error); + Swal.fire('Error', 'Failed to load gateway configurations', 'error'); + } + } + + 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(); + }); + +
- - +