List 50 recently received frames + rssi + snr on website.
rodzic
8070392996
commit
5ff9a350d2
|
@ -159,6 +159,25 @@
|
|||
</form>
|
||||
</article>
|
||||
</section>
|
||||
<section>
|
||||
<div class="grid-container full">
|
||||
<h2 class="u-full-width">Received</h2>
|
||||
</div>
|
||||
<article>
|
||||
<table class="u-full-width">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Frame</th>
|
||||
<th>RSSI</th>
|
||||
<th>SNR</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="receivedFrames">
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</article>
|
||||
</section>
|
||||
<section>
|
||||
<div class="grid-container full">
|
||||
<h2 class="u-full-width">Actions</h2>
|
||||
|
|
|
@ -39,6 +39,29 @@ window.onload = function () {
|
|||
};
|
||||
xhttp.open("GET", "/cfg", true);
|
||||
xhttp.send();
|
||||
var xhttpFramesList = new XMLHttpRequest();
|
||||
xhttpFramesList.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
const response = JSON.parse(this.responseText);
|
||||
let tbody = document.getElementById('receivedFrames');
|
||||
tbody.innerHTML = '';
|
||||
for (const frameInfo of response['received']) {
|
||||
let tr = document.createElement('tr');
|
||||
let td_p = document.createElement('td');
|
||||
td_p.innerHTML = frameInfo['packet'];
|
||||
tr.appendChild(td_p);
|
||||
let td_r = document.createElement('td');
|
||||
td_r.innerHTML = frameInfo['rssi'];
|
||||
tr.appendChild(td_r);
|
||||
let td_s = document.createElement('td');
|
||||
td_s.innerHTML = frameInfo['snr'];
|
||||
tr.appendChild(td_s);
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttpFramesList.open("GET", "/received_list", true);
|
||||
xhttpFramesList.send();
|
||||
};
|
||||
|
||||
function onFileChange(obj){
|
||||
|
|
|
@ -15,5 +15,14 @@ typedef struct {
|
|||
String callsign;
|
||||
} tWebServerCfg;
|
||||
|
||||
typedef struct {
|
||||
String *packet;
|
||||
int RSSI;
|
||||
int SNR;
|
||||
} tReceivedPacketData;
|
||||
|
||||
|
||||
extern QueueHandle_t webListReceivedQueue;
|
||||
|
||||
[[noreturn]] void taskWebServer(void *parameter);
|
||||
#endif
|
|
@ -423,11 +423,33 @@ void sendToTNC(const String& TNC2FormatedFrame) {
|
|||
auto *buffer = new String();
|
||||
buffer->concat(TNC2FormatedFrame);
|
||||
if (xQueueSend(tncReceivedQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS){
|
||||
// remove buffer on error
|
||||
delete buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(ENABLE_WIFI)
|
||||
/**
|
||||
*
|
||||
* @param TNC2FormatedFrame
|
||||
*/
|
||||
void sendToWebList(const String& TNC2FormatedFrame, const int RSSI, const int SNR) {
|
||||
if (webListReceivedQueue){
|
||||
auto *receivedPacketData = new tReceivedPacketData();
|
||||
receivedPacketData->packet = new String();
|
||||
receivedPacketData->packet->concat(TNC2FormatedFrame);
|
||||
receivedPacketData->RSSI = RSSI;
|
||||
receivedPacketData->SNR = SNR;
|
||||
|
||||
if (xQueueSend(webListReceivedQueue, &receivedPacketData, (1000 / portTICK_PERIOD_MS)) != pdPASS){
|
||||
// remove buffer on error
|
||||
delete receivedPacketData->packet;
|
||||
delete receivedPacketData;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
String prepareCallsign(const String& callsign){
|
||||
String tmpString = "";
|
||||
|
@ -839,6 +861,9 @@ void loop() {
|
|||
#ifdef KISS_PROTOCOL
|
||||
sendToTNC(loraReceivedFrameString);
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
sendToWebList(loraReceivedFrameString, rf95.lastRssi(), rf95.lastSNR());
|
||||
#endif
|
||||
syslog_log(LOG_INFO, String("Received LoRa: '") + loraReceivedFrameString + "', RSSI:" + rf95.lastRssi() + ", SNR: " + rf95.lastSNR());
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <list>
|
||||
#include "taskWebServer.h"
|
||||
#include "preference_storage.h"
|
||||
#include "syslog_log.h"
|
||||
|
@ -11,6 +12,9 @@ extern const char web_style_css_end[] asm("_binary_data_embed_style_css_out_end"
|
|||
extern const char web_js_js[] asm("_binary_data_embed_js_js_out_start");
|
||||
extern const char web_js_js_end[] asm("_binary_data_embed_js_js_out_end");
|
||||
|
||||
QueueHandle_t webListReceivedQueue = nullptr;
|
||||
std::list <tReceivedPacketData*> receivedPackets;
|
||||
const int MAX_RECEIVED_LIST_SIZE = 50;
|
||||
|
||||
String apSSID = "";
|
||||
String apPassword = "xxxxxxxxxx";
|
||||
|
@ -46,7 +50,10 @@ String jsonLineFromPreferenceInt(const char *preferenceName, bool last=false){
|
|||
return String("\"") + preferenceName + "\":" + (preferences.getInt(preferenceName)) + (last ? + R"()" : + R"(,)");
|
||||
}
|
||||
String jsonLineFromString(const char *name, const char *value, bool last=false){
|
||||
return String("\"") + name + "\":" + jsonEscape(value) + (last ? + R"()" : + R"(,)");
|
||||
return String("\"") + name + "\":\"" + jsonEscape(value) + "\"" + (last ? + R"()" : + R"(,)");
|
||||
}
|
||||
String jsonLineFromInt(const char *name, const int value, bool last=false){
|
||||
return String("\"") + name + "\":" + String(value) + (last ? + R"()" : + R"(,)");
|
||||
}
|
||||
|
||||
void handle_NotFound(){
|
||||
|
@ -134,14 +141,32 @@ void handle_Cfg() {
|
|||
jsonData += jsonLineFromPreferenceInt(PREF_DEV_SHOW_RX_TIME);
|
||||
jsonData += jsonLineFromPreferenceBool(PREF_DEV_AUTO_SHUT);
|
||||
jsonData += jsonLineFromPreferenceInt(PREF_DEV_AUTO_SHUT_PRESET);
|
||||
jsonData += jsonLineFromString("FreeHeap", String(ESP.getFreeHeap()).c_str());
|
||||
jsonData += jsonLineFromString("HeapSize", String(ESP.getHeapSize()).c_str());
|
||||
jsonData += jsonLineFromString("FreeSketchSpace", String(ESP.getFreeSketchSpace()).c_str(), true);
|
||||
jsonData += jsonLineFromInt("FreeHeap", ESP.getFreeHeap());
|
||||
jsonData += jsonLineFromInt("HeapSize", ESP.getHeapSize());
|
||||
jsonData += jsonLineFromInt("FreeSketchSpace", ESP.getFreeSketchSpace(), true);
|
||||
|
||||
jsonData += "}";
|
||||
server.send(200,"application/json", jsonData);
|
||||
}
|
||||
|
||||
void handle_ReceivedList() {
|
||||
String jsonData = "{\"received\": [";
|
||||
auto count = receivedPackets.size();
|
||||
for (auto element: receivedPackets){
|
||||
jsonData += "{";
|
||||
jsonData += jsonLineFromString("packet", element->packet->c_str());
|
||||
jsonData += jsonLineFromInt("rssi", element->RSSI);
|
||||
jsonData += jsonLineFromInt("snr", element->SNR, true);
|
||||
jsonData += "}";
|
||||
count--;
|
||||
if (count){
|
||||
jsonData += ",";
|
||||
}
|
||||
}
|
||||
jsonData += "]}";
|
||||
server.send(200,"application/json", jsonData);
|
||||
}
|
||||
|
||||
void handle_SaveAPRSCfg() {
|
||||
if (server.hasArg(PREF_APRS_CALLSIGN) && !server.arg(PREF_APRS_CALLSIGN).isEmpty()){
|
||||
preferences.putString(PREF_APRS_CALLSIGN, server.arg(PREF_APRS_CALLSIGN));
|
||||
|
@ -204,6 +229,7 @@ void handle_saveDeviceCfg(){
|
|||
server.on("/save_wifi_cfg", handle_SaveWifiCfg);
|
||||
server.on("/reboot", handle_Reboot);
|
||||
server.on("/cfg", handle_Cfg);
|
||||
server.on("/received_list", handle_ReceivedList);
|
||||
server.on("/save_aprs_cfg", handle_SaveAPRSCfg);
|
||||
server.on("/save_device_cfg", handle_saveDeviceCfg);
|
||||
server.on("/restore", handle_Restore);
|
||||
|
@ -274,8 +300,30 @@ void handle_saveDeviceCfg(){
|
|||
#endif
|
||||
}
|
||||
|
||||
webListReceivedQueue = xQueueCreate(4,sizeof(tReceivedPacketData *));
|
||||
|
||||
|
||||
tReceivedPacketData *receivedPacketData = nullptr;
|
||||
|
||||
while (true){
|
||||
server.handleClient();
|
||||
if (xQueueReceive(webListReceivedQueue, &receivedPacketData, (1 / portTICK_PERIOD_MS)) == pdPASS) {
|
||||
auto *receivedPacketToQueue = new tReceivedPacketData();
|
||||
receivedPacketToQueue->packet = new String();
|
||||
receivedPacketToQueue->packet->concat(*receivedPacketData->packet);
|
||||
receivedPacketToQueue->RSSI = receivedPacketData->RSSI;
|
||||
receivedPacketToQueue->SNR = receivedPacketData->SNR;
|
||||
receivedPackets.push_back(receivedPacketToQueue);
|
||||
if (receivedPackets.size() > MAX_RECEIVED_LIST_SIZE){
|
||||
auto *packetDataToDelete = receivedPackets.front();
|
||||
delete packetDataToDelete->packet;
|
||||
delete packetDataToDelete;
|
||||
receivedPackets.pop_front();
|
||||
}
|
||||
delete receivedPacketData->packet;
|
||||
delete receivedPacketData;
|
||||
}
|
||||
|
||||
vTaskDelay(5/portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue