Merge pull request #33 from Qyon/master_sq9mdd
Start AP if wifi not available 30 seconds
This commit is contained in:
commit
d9ae7f0fd0
|
|
@ -159,6 +159,26 @@
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
<section>
|
||||||
|
<div class="grid-container full">
|
||||||
|
<h2 class="u-full-width">Received</h2>
|
||||||
|
</div>
|
||||||
|
<article>
|
||||||
|
<table class="u-full-width">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Time (UTC)</th>
|
||||||
|
<th>Frame</th>
|
||||||
|
<th>RSSI</th>
|
||||||
|
<th>SNR</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="receivedFrames">
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<div class="grid-container full">
|
<div class="grid-container full">
|
||||||
<h2 class="u-full-width">Actions</h2>
|
<h2 class="u-full-width">Actions</h2>
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,32 @@ window.onload = function () {
|
||||||
};
|
};
|
||||||
xhttp.open("GET", "/cfg", true);
|
xhttp.open("GET", "/cfg", true);
|
||||||
xhttp.send();
|
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_t = document.createElement('td');
|
||||||
|
td_t.innerHTML = frameInfo['time'];
|
||||||
|
tr.appendChild(td_t);
|
||||||
|
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){
|
function onFileChange(obj){
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,15 @@ typedef struct {
|
||||||
String callsign;
|
String callsign;
|
||||||
} tWebServerCfg;
|
} tWebServerCfg;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
struct tm rxTime;
|
||||||
|
String *packet;
|
||||||
|
int RSSI;
|
||||||
|
int SNR;
|
||||||
|
} tReceivedPacketData;
|
||||||
|
|
||||||
|
|
||||||
|
extern QueueHandle_t webListReceivedQueue;
|
||||||
|
|
||||||
[[noreturn]] void taskWebServer(void *parameter);
|
[[noreturn]] void taskWebServer(void *parameter);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -423,11 +423,34 @@ void sendToTNC(const String& TNC2FormatedFrame) {
|
||||||
auto *buffer = new String();
|
auto *buffer = new String();
|
||||||
buffer->concat(TNC2FormatedFrame);
|
buffer->concat(TNC2FormatedFrame);
|
||||||
if (xQueueSend(tncReceivedQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS){
|
if (xQueueSend(tncReceivedQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS){
|
||||||
|
// remove buffer on error
|
||||||
delete buffer;
|
delete buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
||||||
|
getLocalTime(&receivedPacketData->rxTime);
|
||||||
|
|
||||||
|
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 prepareCallsign(const String& callsign){
|
||||||
String tmpString = "";
|
String tmpString = "";
|
||||||
|
|
@ -839,6 +862,9 @@ void loop() {
|
||||||
#ifdef KISS_PROTOCOL
|
#ifdef KISS_PROTOCOL
|
||||||
sendToTNC(loraReceivedFrameString);
|
sendToTNC(loraReceivedFrameString);
|
||||||
#endif
|
#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());
|
syslog_log(LOG_INFO, String("Received LoRa: '") + loraReceivedFrameString + "', RSSI:" + rf95.lastRssi() + ", SNR: " + rf95.lastSNR());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
#include <list>
|
||||||
#include "taskWebServer.h"
|
#include "taskWebServer.h"
|
||||||
#include "preference_storage.h"
|
#include "preference_storage.h"
|
||||||
#include "syslog_log.h"
|
#include "syslog_log.h"
|
||||||
|
#include <time.h>
|
||||||
/**
|
/**
|
||||||
* @see board_build.embed_txtfiles in platformio.ini
|
* @see board_build.embed_txtfiles in platformio.ini
|
||||||
*/
|
*/
|
||||||
|
|
@ -11,6 +13,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[] asm("_binary_data_embed_js_js_out_start");
|
||||||
extern const char web_js_js_end[] asm("_binary_data_embed_js_js_out_end");
|
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 apSSID = "";
|
||||||
String apPassword = "xxxxxxxxxx";
|
String apPassword = "xxxxxxxxxx";
|
||||||
|
|
@ -46,7 +51,10 @@ String jsonLineFromPreferenceInt(const char *preferenceName, bool last=false){
|
||||||
return String("\"") + preferenceName + "\":" + (preferences.getInt(preferenceName)) + (last ? + R"()" : + R"(,)");
|
return String("\"") + preferenceName + "\":" + (preferences.getInt(preferenceName)) + (last ? + R"()" : + R"(,)");
|
||||||
}
|
}
|
||||||
String jsonLineFromString(const char *name, const char *value, bool last=false){
|
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(){
|
void handle_NotFound(){
|
||||||
|
|
@ -134,14 +142,35 @@ void handle_Cfg() {
|
||||||
jsonData += jsonLineFromPreferenceInt(PREF_DEV_SHOW_RX_TIME);
|
jsonData += jsonLineFromPreferenceInt(PREF_DEV_SHOW_RX_TIME);
|
||||||
jsonData += jsonLineFromPreferenceBool(PREF_DEV_AUTO_SHUT);
|
jsonData += jsonLineFromPreferenceBool(PREF_DEV_AUTO_SHUT);
|
||||||
jsonData += jsonLineFromPreferenceInt(PREF_DEV_AUTO_SHUT_PRESET);
|
jsonData += jsonLineFromPreferenceInt(PREF_DEV_AUTO_SHUT_PRESET);
|
||||||
jsonData += jsonLineFromString("FreeHeap", String(ESP.getFreeHeap()).c_str());
|
jsonData += jsonLineFromInt("FreeHeap", ESP.getFreeHeap());
|
||||||
jsonData += jsonLineFromString("HeapSize", String(ESP.getHeapSize()).c_str());
|
jsonData += jsonLineFromInt("HeapSize", ESP.getHeapSize());
|
||||||
jsonData += jsonLineFromString("FreeSketchSpace", String(ESP.getFreeSketchSpace()).c_str(), true);
|
jsonData += jsonLineFromInt("FreeSketchSpace", ESP.getFreeSketchSpace(), true);
|
||||||
|
|
||||||
jsonData += "}";
|
jsonData += "}";
|
||||||
server.send(200,"application/json", jsonData);
|
server.send(200,"application/json", jsonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_ReceivedList() {
|
||||||
|
String jsonData = "{\"received\": [";
|
||||||
|
auto count = receivedPackets.size();
|
||||||
|
for (auto element: receivedPackets){
|
||||||
|
jsonData += "{";
|
||||||
|
char buf[64];
|
||||||
|
strftime(buf, 64, "%Y.%m.%d %H:%M:%S", &element->rxTime);
|
||||||
|
jsonData += jsonLineFromString("time", buf);
|
||||||
|
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() {
|
void handle_SaveAPRSCfg() {
|
||||||
if (server.hasArg(PREF_APRS_CALLSIGN) && !server.arg(PREF_APRS_CALLSIGN).isEmpty()){
|
if (server.hasArg(PREF_APRS_CALLSIGN) && !server.arg(PREF_APRS_CALLSIGN).isEmpty()){
|
||||||
preferences.putString(PREF_APRS_CALLSIGN, server.arg(PREF_APRS_CALLSIGN));
|
preferences.putString(PREF_APRS_CALLSIGN, server.arg(PREF_APRS_CALLSIGN));
|
||||||
|
|
@ -204,6 +233,7 @@ void handle_saveDeviceCfg(){
|
||||||
server.on("/save_wifi_cfg", handle_SaveWifiCfg);
|
server.on("/save_wifi_cfg", handle_SaveWifiCfg);
|
||||||
server.on("/reboot", handle_Reboot);
|
server.on("/reboot", handle_Reboot);
|
||||||
server.on("/cfg", handle_Cfg);
|
server.on("/cfg", handle_Cfg);
|
||||||
|
server.on("/received_list", handle_ReceivedList);
|
||||||
server.on("/save_aprs_cfg", handle_SaveAPRSCfg);
|
server.on("/save_aprs_cfg", handle_SaveAPRSCfg);
|
||||||
server.on("/save_device_cfg", handle_saveDeviceCfg);
|
server.on("/save_device_cfg", handle_saveDeviceCfg);
|
||||||
server.on("/restore", handle_Restore);
|
server.on("/restore", handle_Restore);
|
||||||
|
|
@ -244,12 +274,17 @@ void handle_saveDeviceCfg(){
|
||||||
if (!wifi_ssid.length()){
|
if (!wifi_ssid.length()){
|
||||||
WiFi.softAP(apSSID.c_str(), apPassword.c_str());
|
WiFi.softAP(apSSID.c_str(), apPassword.c_str());
|
||||||
} else {
|
} else {
|
||||||
|
int retryWifi = 0;
|
||||||
WiFi.begin(wifi_ssid.c_str(), wifi_password.length() ? wifi_password.c_str() : nullptr);
|
WiFi.begin(wifi_ssid.c_str(), wifi_password.length() ? wifi_password.c_str() : nullptr);
|
||||||
Serial.println("Connecting to " + wifi_ssid);
|
Serial.println("Connecting to " + wifi_ssid);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.print("Not connected: ");
|
Serial.print("Not connected: ");
|
||||||
Serial.println((int)WiFi.status());
|
Serial.println((int)WiFi.status());
|
||||||
vTaskDelay(500/portTICK_PERIOD_MS);
|
vTaskDelay(500/portTICK_PERIOD_MS);
|
||||||
|
retryWifi += 1;
|
||||||
|
if (retryWifi > 60) {
|
||||||
|
WiFi.softAP(apSSID.c_str(), apPassword.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println("Connected. IP: " + WiFi.localIP().toString());
|
Serial.println("Connected. IP: " + WiFi.localIP().toString());
|
||||||
#ifdef ENABLE_SYSLOG
|
#ifdef ENABLE_SYSLOG
|
||||||
|
|
@ -259,7 +294,17 @@ void handle_saveDeviceCfg(){
|
||||||
syslog.defaultPriority(LOG_KERN);
|
syslog.defaultPriority(LOG_KERN);
|
||||||
syslog_log(LOG_INFO, "Connected. IP: " + WiFi.localIP().toString());
|
syslog_log(LOG_INFO, "Connected. IP: " + WiFi.localIP().toString());
|
||||||
#endif
|
#endif
|
||||||
|
configTime(0, 0, "pool.ntp.org");
|
||||||
|
#ifdef ENABLE_SYSLOG
|
||||||
|
struct tm timeinfo{};
|
||||||
|
if(!getLocalTime(&timeinfo)){
|
||||||
|
syslog_log(LOG_WARNING, "Failed to obtain time");
|
||||||
|
} else {
|
||||||
|
char buf[64];
|
||||||
|
strftime(buf, 64, "%A, %B %d %Y %H:%M:%S", &timeinfo);
|
||||||
|
syslog_log(LOG_INFO, String("Time: ") + String(buf));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
@ -274,8 +319,31 @@ void handle_saveDeviceCfg(){
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webListReceivedQueue = xQueueCreate(4,sizeof(tReceivedPacketData *));
|
||||||
|
|
||||||
|
|
||||||
|
tReceivedPacketData *receivedPacketData = nullptr;
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
server.handleClient();
|
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;
|
||||||
|
receivedPacketToQueue->rxTime = receivedPacketData->rxTime;
|
||||||
|
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);
|
vTaskDelay(5/portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue