mirror of
https://github.com/skinnyrad/Lora-Scanner.git
synced 2026-03-28 17:43:00 +01:00
Merge pull request #17 from skinnyrad/feat/gatewaySaveConfig
Feat: Auto save of gateway config
This commit is contained in:
@@ -80,6 +80,8 @@ The 'Configure LoRaWAN Gateway' section allows you to set up to ten Dragino LPS8
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
The gateway configuration will automatically be saved to a file named 'gateway_config.json'. This file gets loaded each time the application runs. If you would like to save multiple configurations, copy the 'gateway_config.json' to a new file for later use.
|
||||||
|
|
||||||
## Analysis Mode
|
## Analysis Mode
|
||||||
|
|
||||||
Analyze LoRa traffic received at 433, 868, or 915 MHz with ‘Analysis Mode’. Click the desired frequency to get started. Once connected to your LoRa receiver, traffic will automatically be streamed to the web page for analysis. To disconnect a receiver, click the 'Disconnect Serial Port' button.
|
Analyze LoRa traffic received at 433, 868, or 915 MHz with ‘Analysis Mode’. Click the desired frequency to get started. Once connected to your LoRa receiver, traffic will automatically be streamed to the web page for analysis. To disconnect a receiver, click the 'Disconnect Serial Port' button.
|
||||||
|
|||||||
53
app.py
53
app.py
@@ -14,6 +14,9 @@ from io import StringIO, BytesIO
|
|||||||
import csv
|
import csv
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
from ipaddress import ip_address, AddressValueError
|
from ipaddress import ip_address, AddressValueError
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
socketio = SocketIO(app)
|
socketio = SocketIO(app)
|
||||||
@@ -41,6 +44,7 @@ frequency = lambda port: {'port1': 433, 'port2': 868,'port3': 915}.get(port, Non
|
|||||||
surveydata = {}
|
surveydata = {}
|
||||||
parsed_entries = set()
|
parsed_entries = set()
|
||||||
used_ports = set()
|
used_ports = set()
|
||||||
|
CONFIG_FILE = 'gateway_config.json'
|
||||||
|
|
||||||
def read_serial_data(port, ser, buffer):
|
def read_serial_data(port, ser, buffer):
|
||||||
"""
|
"""
|
||||||
@@ -728,25 +732,63 @@ def set_gateways():
|
|||||||
global gateway_ips
|
global gateway_ips
|
||||||
data = request.form
|
data = request.form
|
||||||
|
|
||||||
# Create an ordered dictionary of gateways
|
# Update gateway IPs
|
||||||
ordered_gateways = {}
|
ordered_gateways = {}
|
||||||
for i in range(1, 11):
|
for i in range(1, 11):
|
||||||
key = f'gateway{i}'
|
key = f'gateway{i}'
|
||||||
input_ip = data.get(key, '').strip()
|
input_ip = data.get(key, '').strip()
|
||||||
ordered_gateways[key] = input_ip
|
ordered_gateways[key] = input_ip if input_ip else ''
|
||||||
|
|
||||||
# Update the global gateway_ips with ordered data
|
|
||||||
gateway_ips.update(ordered_gateways)
|
gateway_ips.update(ordered_gateways)
|
||||||
|
|
||||||
for gateway, ip_address in gateway_ips.items():
|
for gateway, ip_address in gateway_ips.items():
|
||||||
print(f"Gateway {gateway} has IP address: {ip_address}")
|
print(f"Gateway {gateway} has IP address: {ip_address}")
|
||||||
|
|
||||||
return jsonify({"message": "Gateway IPs updated successfully"}), 200
|
# Save configuration
|
||||||
|
if save_gateway_config():
|
||||||
|
return jsonify({"message": "Gateway IPs updated and saved successfully"}), 200
|
||||||
|
else:
|
||||||
|
return jsonify({"message": "Gateway IPs updated but failed to save configuration"}), 200
|
||||||
|
|
||||||
@app.route('/get_gateways', methods=['GET'])
|
@app.route('/get_gateways', methods=['GET'])
|
||||||
def get_gateways():
|
def get_gateways():
|
||||||
|
"""
|
||||||
|
Retrieves the current IP addresses of the gateways.
|
||||||
|
|
||||||
|
This function handles the '/get_gateways' URL route and returns a JSON
|
||||||
|
response containing the IP addresses of the configured gateways.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Response: A JSON response with the current gateway IPs, where each key is
|
||||||
|
a gateway identifier and the value is the corresponding IP address.
|
||||||
|
"""
|
||||||
return jsonify(gateway_ips)
|
return jsonify(gateway_ips)
|
||||||
|
|
||||||
|
def save_gateway_config():
|
||||||
|
"""
|
||||||
|
Saves the current gateway configuration to a JSON file.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(CONFIG_FILE, 'w') as f:
|
||||||
|
json.dump(gateway_ips, f)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error saving gateway configuration: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def load_gateway_config():
|
||||||
|
"""
|
||||||
|
Loads the gateway configuration from a JSON file.
|
||||||
|
"""
|
||||||
|
global gateway_ips
|
||||||
|
try:
|
||||||
|
if os.path.exists(CONFIG_FILE):
|
||||||
|
with open(CONFIG_FILE, 'r') as f:
|
||||||
|
loaded_config = json.load(f)
|
||||||
|
gateway_ips.update(loaded_config)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error loading gateway configuration: {e}")
|
||||||
|
|
||||||
@app.route('/downloadPackets', methods=['GET'])
|
@app.route('/downloadPackets', methods=['GET'])
|
||||||
def downloadPackets():
|
def downloadPackets():
|
||||||
"""
|
"""
|
||||||
@@ -772,5 +814,6 @@ def downloadPackets():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
load_gateway_config()
|
||||||
Timer(30, parse_and_store_data).start()
|
Timer(30, parse_and_store_data).start()
|
||||||
socketio.run(app, debug=True)
|
socketio.run(app, debug=True)
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 196 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 174 KiB |
@@ -695,11 +695,11 @@
|
|||||||
<li>Once configured, the application automatically retrieves and stores LoRaWAN traffic from each active gateway.</li>
|
<li>Once configured, the application automatically retrieves and stores LoRaWAN traffic from each active gateway.</li>
|
||||||
<li>Access and analyze stored traffic in 'survey mode'.</li>
|
<li>Access and analyze stored traffic in 'survey mode'.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="note"><em>Empty values will be ignored, and the Gateway IP address will remain unchanged</em></p>
|
<p class="note"><em>Empty values will erase that particular gateway IP address</em></p>
|
||||||
</div>
|
</div>
|
||||||
<form id="gatewayForm" class="mt-3">
|
<form id="gatewayForm" class="mt-3">
|
||||||
<div id="gatewayInputs"></div>
|
<div id="gatewayInputs"></div>
|
||||||
<button type="button" class="btn btn-primary mt-3" onclick="submitGatewayForm()">Update Gateways</button>
|
<button type="button" class="btn btn-primary mt-3" onclick="submitGatewayForm()">Configure Gateways</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user