mirror of
https://github.com/skinnyrad/Lora-Scanner.git
synced 2026-03-28 17:43:00 +01:00
Feat: Adding Gateway Configuration
This commit is contained in:
35
app.py
35
app.py
@@ -9,6 +9,7 @@ from collections import deque
|
||||
import re
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import ipaddress
|
||||
|
||||
app = Flask(__name__)
|
||||
socketio = SocketIO(app)
|
||||
@@ -20,6 +21,9 @@ port3_status = True
|
||||
global ser1
|
||||
global ser2
|
||||
global ser3
|
||||
gateway_ips = {'gateway1': '192.168.0.101',
|
||||
'gateway2': '192.168.0.102',
|
||||
'gateway3': '192.168.0.103'}
|
||||
frequency = lambda port: {'port1': 433, 'port2': 868,'port3': 915}.get(port, None)
|
||||
surveydata = {}
|
||||
parsed_entries = set()
|
||||
@@ -79,16 +83,35 @@ def read_serial_data(port, ser, buffer):
|
||||
#print(f"Error: {e}")
|
||||
pass
|
||||
|
||||
@app.route('/set_gateways', methods=['POST'])
|
||||
def set_gateways():
|
||||
global gateway_ips
|
||||
data = request.form
|
||||
for key in ['gateway1', 'gateway2', 'gateway3']:
|
||||
input_ip = data.get(key, '').strip()
|
||||
if input_ip: # Proceed only if the input is not empty
|
||||
try:
|
||||
# Validate the IP address
|
||||
ipaddress.ip_address(input_ip)
|
||||
# Update the IP address if valid
|
||||
gateway_ips[key] = input_ip
|
||||
except ValueError:
|
||||
# Return an error if the IP address is invalid
|
||||
return jsonify({"error": f"Invalid IP address provided for {key}"}), 400
|
||||
|
||||
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
|
||||
|
||||
def parse_and_store_data():
|
||||
global surveydata
|
||||
global parsed_entries
|
||||
|
||||
global gateway_ips
|
||||
# Include the port number (8000) in your gateway URLs
|
||||
gateway_urls = [
|
||||
"http://192.168.0.101:8000/cgi-bin/log-traffic.has", # Gateway 1 (915 MHz)
|
||||
"http://192.168.0.102:8000/cgi-bin/log-traffic.has", # Gateway 2 (868 MHz)
|
||||
"http://192.168.0.103:8000/cgi-bin/log-traffic.has" # Gateway 3 (915 MHz)
|
||||
f"http://{gateway_ips['gateway1']}:8000/cgi-bin/log-traffic.has", # Gateway 1
|
||||
f"http://{gateway_ips['gateway2']}:8000/cgi-bin/log-traffic.has", # Gateway 2
|
||||
f"http://{gateway_ips['gateway3']}:8000/cgi-bin/log-traffic.has" # Gateway 3
|
||||
]
|
||||
|
||||
headers = {
|
||||
@@ -105,7 +128,7 @@ def parse_and_store_data():
|
||||
|
||||
for url in gateway_urls:
|
||||
try:
|
||||
response = requests.get(url, headers=headers)
|
||||
response = requests.get(url, headers=headers, timeout=10)
|
||||
if response.status_code == 200:
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
table = soup.find('table')
|
||||
@@ -157,7 +180,7 @@ def parse_and_store_data():
|
||||
|
||||
|
||||
# Schedule the next call to this function
|
||||
Timer(30, parse_and_store_data).start() # Call this function every 60 seconds
|
||||
Timer(30, parse_and_store_data).start() # Call this function every 30 seconds
|
||||
|
||||
|
||||
def extract_dev_id(formatted_row):
|
||||
|
||||
BIN
static/assets/img/lorawan.webp
Normal file
BIN
static/assets/img/lorawan.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 775 KiB |
@@ -32,7 +32,7 @@
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item"><a class="nav-link js-scroll-trigger" href="#about">About</a></li>
|
||||
<li class="nav-item"><a class="nav-link js-scroll-trigger" href="#about">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link js-scroll-trigger" href="/analysis">Analysis Mode</a></li>
|
||||
<li class="nav-item"><a class="nav-link js-scroll-trigger" href="/survey">Survey Mode</a></li>
|
||||
<li class="nav-item"><a class="nav-link js-scroll-trigger" href="/tracking">Tracking Mode</a></li>
|
||||
@@ -60,7 +60,75 @@
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Add this form within the body where it fits best, possibly under the About section -->
|
||||
<section class="resume-section">
|
||||
<div class="resume-section-content">
|
||||
<h2 class="mb-0" style="text-align: center;">LoRaWAN Gateway Configuration</h2><br>
|
||||
<img src="static/assets/img/lorawan.webp" style="width:100%; "><br><br>
|
||||
<div style="display: flex; justify-content: center; margin-top: 20px;"><button class="transmit-button" id="configureGatewayBtn">Configure Gateway</button></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('configureGatewayBtn').addEventListener('click', function() {
|
||||
let gatewayIPs = {};
|
||||
|
||||
const ipPrompt = (title) => {
|
||||
return Swal.fire({
|
||||
title: title,
|
||||
input: 'text',
|
||||
inputPlaceholder: 'Leave empty to keep current IP',
|
||||
inputValidator: (value) => {
|
||||
if (value && !value.match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/)) {
|
||||
return 'Please enter a valid IP address or leave it empty';
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
ipPrompt('Enter Gateway 1 IP Address').then((result) => {
|
||||
if (result.value) gatewayIPs.gateway1 = result.value;
|
||||
|
||||
ipPrompt('Enter Gateway 2 IP Address').then((result) => {
|
||||
if (result.value) gatewayIPs.gateway2 = result.value;
|
||||
|
||||
ipPrompt('Enter Gateway 3 IP Address').then((result) => {
|
||||
if (result.value) gatewayIPs.gateway3 = result.value;
|
||||
|
||||
// Now send the IPs to the server only if they are not undefined
|
||||
let queryString = Object.keys(gatewayIPs).reduce((acc, key) => {
|
||||
if (gatewayIPs[key] !== undefined) {
|
||||
acc.push(`${key}=${encodeURIComponent(gatewayIPs[key])}`);
|
||||
}
|
||||
return acc;
|
||||
}, []).join('&');
|
||||
|
||||
if (queryString) {
|
||||
fetch('/set_gateways', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: queryString
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => Swal.fire('Success', 'Gateway IPs updated successfully', 'success'))
|
||||
.catch(error => Swal.fire('Error', 'There was an issue updating the Gateway IPs', 'error'));
|
||||
} else {
|
||||
Swal.fire('No Changes', 'No IP addresses were changed.', 'info');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<!-- Bootstrap core JS-->
|
||||
<script src="static/js/bootstrap.bundle.min.js"></script>
|
||||
<!-- Core theme JS-->
|
||||
|
||||
Reference in New Issue
Block a user