mirror of
https://github.com/skinnyrad/Lora-Scanner.git
synced 2026-03-28 17:43:00 +01:00
Adding a table for survey mode
This commit is contained in:
36
app.py
36
app.py
@@ -19,25 +19,27 @@ global ser2
|
||||
global ser3
|
||||
global_dataframe = pd.DataFrame(columns=['Device Name', 'Frequency', 'Signal Strength', 'Plaintext'])
|
||||
frequency = lambda port: {'port1': 433, 'port2': 868,'port3': 915}.get(port, None)
|
||||
|
||||
surveydata = {'Test Device': [915, -20, 'Some Plaintext information'],}
|
||||
|
||||
def read_serial_data(port, ser, buffer):
|
||||
global global_dataframe
|
||||
global surveydata
|
||||
while True:
|
||||
try:
|
||||
if ser.in_waiting > 0:
|
||||
data = ser.readline().decode('utf-8').strip()
|
||||
buffer.append(data)
|
||||
socketio.emit(f'serial_data_{port}', {'data': data})
|
||||
socketio.emit(f'serial_data_{port}', {'data': data})
|
||||
|
||||
|
||||
if (global_dataframe['Device Name'] == 'Unknown Raw LoRa Devices').any():
|
||||
pass
|
||||
else:
|
||||
pandasdata = {'Device Name': 'Unknown Raw LoRa Devices', 'Frequency': frequency(port)}
|
||||
global_dataframe = global_dataframe.append(pandasdata, ignore_index=True)
|
||||
'''print(global_dataframe.head())'''
|
||||
|
||||
if frequency(port) == 433 and surveydata.get('Raw LoRa Device 443 MHz') is None:
|
||||
surveydata['Raw LoRa Device 443 MHz'] = [433,0,'']
|
||||
|
||||
elif frequency(port) == 868 and surveydata.get('Raw LoRa Device 868 MHz') is None:
|
||||
surveydata['Raw LoRa Device 868 MHz'] = [868,0,'']
|
||||
|
||||
elif frequency(port) == 915 and surveydata.get('Raw LoRa Device 915 MHz') is None:
|
||||
surveydata['Raw LoRa Device 915 MHz'] = [915,0,'']
|
||||
|
||||
|
||||
if (port == 'port1' and port1_status == False):
|
||||
return
|
||||
if (port == 'port2' and port2_status == False):
|
||||
@@ -47,7 +49,7 @@ def read_serial_data(port, ser, buffer):
|
||||
time.sleep(0.1)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def connect_serial(port,frequency):
|
||||
global ser1
|
||||
@@ -114,7 +116,7 @@ def analysis():
|
||||
|
||||
@app.route('/survey')
|
||||
def survey():
|
||||
return render_template('survey.html', initial_data={port: list(buffer) for port, buffer in serial_buffers.items()})
|
||||
return render_template('survey.html', data=global_dataframe)
|
||||
|
||||
@app.route('/tracking')
|
||||
def tracking():
|
||||
@@ -221,8 +223,12 @@ def checkSer():
|
||||
except:
|
||||
pass
|
||||
return jsonify(result="False")
|
||||
|
||||
|
||||
|
||||
@app.route('/get_table_data')
|
||||
def get_table_data():
|
||||
global surveydata
|
||||
print(surveydata)
|
||||
return jsonify(surveydata)
|
||||
|
||||
if __name__ == '__main__':
|
||||
socketio.run(app, debug=True)
|
||||
|
||||
@@ -11062,4 +11062,23 @@ section.resume-section .resume-section-content {
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
/* Styling for the table */
|
||||
.scrollable-table {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
display: block;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid black;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<!-- Include SweetAlert2 JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
|
||||
</head>
|
||||
<body id="page-top">
|
||||
@@ -45,52 +45,46 @@
|
||||
<!-- About-->
|
||||
<section class="resume-section" id="about">
|
||||
<div class="resume-section-content">
|
||||
<h1 class="mb-0">
|
||||
<h1 class="mb-0" style="text-align: center;">
|
||||
Survey Mode
|
||||
</h1>
|
||||
<h2 class="lead mb-5">Skinny Research and Development</h2>
|
||||
</div>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>DataFrame Table</title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 80%;
|
||||
margin: auto;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #dddddd;
|
||||
text-align: left;
|
||||
padding: 8px;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Device Name</th>
|
||||
<th>Frequency</th>
|
||||
<th>Signal Strength</th>
|
||||
<th>Plaintext</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for index, row in data.iterrows() %}
|
||||
<tr>
|
||||
<td>{{ row['Device Name'] }}</td>
|
||||
<td>{{ row['Frequency'] }}</td>
|
||||
<td>{{ row['Signal Strength'] }}</td>
|
||||
<td>{{ row['Plaintext'] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<br>
|
||||
<div class="scrollable-table">
|
||||
<table id="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Device Name</th>
|
||||
<th>Frequency</th>
|
||||
<th>Signal Strength</th>
|
||||
<th>Recovered Plaintext</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Rows will be inserted here -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Fetch data from Flask route
|
||||
fetch('/get_table_data')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const tableBody = document.getElementById('data-table').getElementsByTagName('tbody')[0];
|
||||
for (let key in data) {
|
||||
let row = tableBody.insertRow();
|
||||
let cell1 = row.insertCell();
|
||||
let cell2 = row.insertCell();
|
||||
let cell3 = row.insertCell();
|
||||
let cell4 = row.insertCell();
|
||||
cell1.innerHTML = key;
|
||||
cell2.innerHTML = data[key][0];
|
||||
cell3.innerHTML = data[key][1];
|
||||
cell4.innerHTML = data[key][2];
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
</script>
|
||||
</section>
|
||||
<hr class="m-0" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user