Merge remote-tracking branch 'origin/gps_out_tcp_test' into master_sq9mdd

pull/45/head
Łukasz Nidecki 2021-06-24 15:35:51 +02:00
commit ed7d68a828
12 zmienionych plików z 180 dodań i 62 usunięć

Wyświetl plik

@ -185,12 +185,17 @@
</div>
<article>
<div class="grid-container quarters">
<form action="/reboot" method="post">
<form action="/shutdown" method="post" onsubmit="return confirmAction('shutdown');">
<div>
<input class="button-primary" type="submit" value="Shutdown">
</div>
</form>
<form action="/reboot" method="post" onsubmit="return confirmAction('reboot');">
<div>
<input class="button-primary" type="submit" value="Reboot">
</div>
</form>
<form action="/restore" method="post">
<form action="/restore" method="post" onsubmit="return confirmAction('do factory reset');">
<div>
<input class="button-primary" type="submit" value="Factory reset">
</div>

Wyświetl plik

@ -113,4 +113,8 @@ function updateFileUpload(event) {
xhr.open('POST', '/update');
xhr.send(data);
}
function confirmAction(actionName) {
return window.confirm('Are you shure want to ' + actionName);
}

Wyświetl plik

@ -2,4 +2,5 @@
#include <TinyGPS++.h>
extern TinyGPSPlus gps;
void taskGPS(void *parameter);
[[noreturn]] void taskGPS(void *parameter);

Wyświetl plik

@ -7,6 +7,7 @@
#endif
#if defined(ENABLE_WIFI)
#include "taskWebServer.h"
#include "wifi_clients.h"
#endif
extern QueueHandle_t tncToSendQueue;
extern QueueHandle_t tncReceivedQueue;

Wyświetl plik

@ -12,6 +12,7 @@ extern BG_RF95 rf95;
#ifdef KISS_PROTOCOL
extern WiFiServer tncServer;
#endif
extern WiFiServer gpsServer;
typedef struct {
String callsign;
} tWebServerCfg;

Wyświetl plik

@ -0,0 +1,13 @@
//
// Created by Admin on 11.06.2021.
//
#ifndef TTGO_T_BEAM_LORA_APRS_WIFI_CLIENTS_H
#define TTGO_T_BEAM_LORA_APRS_WIFI_CLIENTS_H
#include <WiFiClient.h>
#include <WiFiServer.h>
typedef void (*f_connectedClientCallback_t) (WiFiClient *, int, const String *);
void iterateWifiClients(f_connectedClientCallback_t callback, const String *data, WiFiClient * wifiClients[], int maxWifiClients);
void check_for_new_clients(WiFiServer *wiFiServer, WiFiClient * wifiClients[], int maxWifiClients);
#endif //TTGO_T_BEAM_LORA_APRS_WIFI_CLIENTS_H

Wyświetl plik

@ -0,0 +1,27 @@
//
// Created by Admin on 14.06.2021.
//
#ifndef TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H
#define TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H
#include <ArduinoJson.h>
struct SpiRamAllocator {
void* allocate(size_t size) {
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
}
void deallocate(void* pointer) {
heap_caps_free(pointer);
}
void* reallocate(void* ptr, size_t new_size) {
return heap_caps_realloc(ptr, new_size, MALLOC_CAP_SPIRAM);
}
};
using PSRAMJsonDocument = BasicJsonDocument<SpiRamAllocator>;
#endif //TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H

Wyświetl plik

@ -49,6 +49,7 @@ build_flags =
-D 'ENABLE_OLED'
-D 'ENABLE_LED_SIGNALING'
-D 'NETWORK_TNC_PORT=8001'
-D 'NETWORK_GPS_PORT=10110'
-D 'MAX_TIME_TO_NEXT_TX=360000L'
-D 'FIX_BEACON_INTERVAL=1800000L'

Wyświetl plik

@ -1,8 +1,16 @@
#include <taskGPS.h>
#include <SparkFun_Ublox_Arduino_Library.h>
#include <taskWebServer.h>
SFE_UBLOX_GPS myGPS;
#ifdef ENABLE_WIFI
#include "wifi_clients.h"
#define MAX_GPS_WIFI_CLIENTS 6
WiFiClient * gps_clients[MAX_GPS_WIFI_CLIENTS];
#endif
// Pins for GPS
#ifdef T_BEAM_V1_0
static const int RXPin = 12, TXPin = 34;
@ -14,7 +22,7 @@ HardwareSerial gpsSerial(1); // TTGO has HW serial
TinyGPSPlus gps; // The TinyGPS++ object
bool gpsInitialized = false;
void taskGPS(void *parameter) {
[[noreturn]] void taskGPS(void *parameter) {
if (!gpsInitialized){
gpsSerial.begin(GPSBaud, SERIAL_8N1, TXPin, RXPin); //Startup HW serial for GPS
@ -35,9 +43,29 @@ void taskGPS(void *parameter) {
}
}
String gpsDataBuffer = " ";
for (;;) {
check_for_new_clients(&gpsServer, gps_clients, MAX_GPS_WIFI_CLIENTS);
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
char gpsChar = (char)gpsSerial.read();
gps.encode(gpsChar);
#ifdef ENABLE_WIFI
if (gpsChar == '$') {
gpsDataBuffer = String(gpsChar);
} else {
gpsDataBuffer += String(gpsChar);
if (gpsChar == '\n') {
iterateWifiClients([](WiFiClient *client, int clientIdx, const String *data){
if (client->connected()){
client->print(*data);
client->flush();
}
}, &gpsDataBuffer, gps_clients, MAX_GPS_WIFI_CLIENTS);
gpsDataBuffer = "";
}
}
#endif
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}

Wyświetl plik

@ -9,25 +9,6 @@ QueueHandle_t tncReceivedQueue = nullptr;
#ifdef ENABLE_WIFI
#define MAX_WIFI_CLIENTS 6
WiFiClient * clients[MAX_WIFI_CLIENTS];
typedef void (*f_connectedClientCallback_t) (WiFiClient *, int, const String *);
void iterateWifiClients(f_connectedClientCallback_t callback, const String *data){
for (int i=0; i<MAX_WIFI_CLIENTS; i++) {
auto client = clients[i];
if (client != nullptr) {
if (client->connected()) {
callback(client, i, data);
} else {
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("Disconnected client ") + client->remoteIP().toString() + ":" + client->remotePort());
#endif
delete client;
clients[i] = nullptr;
}
}
}
}
#endif
#ifdef ENABLE_WIFI
#define IN_TNC_BUFFERS (2+MAX_WIFI_CLIENTS)
@ -67,7 +48,7 @@ void handleKISSData(char character, int bufferIndex) {
client->print(*data);
client->flush();
}
}, &inTNCData);
}, &inTNCData, clients, MAX_WIFI_CLIENTS);
#endif
#endif
auto *buffer = new String();
@ -103,45 +84,14 @@ void handleKISSData(char character, int bufferIndex) {
}
#endif
#ifdef ENABLE_WIFI
WiFiClient new_client = tncServer.available();
if (new_client.connected()){
bool new_client_handled = false;
for (int i=0; i < MAX_WIFI_CLIENTS; i++) {
auto client = clients[i];
if (client == nullptr) {
client = new WiFiClient(new_client);
clients[i] = client;
new_client_handled = true;
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("New client #") +String(i) + ": " + client->remoteIP().toString() + ":" + client->remotePort());
#endif
break;
}
}
#ifdef ENABLE_WIFI_CLIENT_DEBUG
for (int i = 0; i < MAX_WIFI_CLIENTS; ++i) {
auto client = clients[i];
check_for_new_clients(&tncServer, clients, MAX_WIFI_CLIENTS);
if (client != nullptr){
Serial.println(String("Client #") +String(i) + ": " + client->remoteIP().toString() + ":" + client->remotePort());
}
}
#endif
if (!new_client_handled){
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("Refusing client "));
#endif
new_client.stop();
}
}
iterateWifiClients([](WiFiClient * client, int clientIdx, const String * unused){
while (client->available() > 0) {
char character = client->read();
handleKISSData(character, 2+clientIdx);
}
}, nullptr);
}, nullptr, clients, MAX_WIFI_CLIENTS);
#endif
if (xQueueReceive(tncReceivedQueue, &loraReceivedFrameString, (1 / portTICK_PERIOD_MS)) == pdPASS) {
@ -158,7 +108,7 @@ void handleKISSData(char character, int bufferIndex) {
client->print(*data);
client->flush();
}
}, &kissEncoded);
}, &kissEncoded, clients, MAX_WIFI_CLIENTS);
#endif
delete loraReceivedFrameString;

Wyświetl plik

@ -2,6 +2,7 @@
#include "taskWebServer.h"
#include "preference_storage.h"
#include "syslog_log.h"
#include "PSRAMJsonDocument.h"
#include <time.h>
#include <ArduinoJson.h>
@ -17,7 +18,7 @@ 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 = 10;
const int MAX_RECEIVED_LIST_SIZE = 50;
String apSSID = "";
String apPassword = "xxxxxxxxxx";
@ -25,6 +26,7 @@ WebServer server(80);
#ifdef KISS_PROTOCOL
WiFiServer tncServer(NETWORK_TNC_PORT);
#endif
WiFiServer gpsServer(NETWORK_GPS_PORT);
#ifdef ENABLE_SYSLOG
// A UDP instance to let us send and receive packets over UDP
@ -34,6 +36,12 @@ WebServer server(80);
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
#endif
#ifdef T_BEAM_V1_0
#include <axp20x.h>
extern AXP20X_Class axp;
#endif
void sendCacheHeader() { server.sendHeader("Cache-Control", "max-age=3600"); }
void sendGzipHeader() { server.sendHeader("Content-Encoding", "gzip"); }
@ -115,9 +123,20 @@ void handle_SaveWifiCfg() {
void handle_Reboot() {
server.sendHeader("Location", "/");
server.send(302,"text/html", "");
server.close();
ESP.restart();
}
void handle_Shutdown() {
#ifdef T_BEAM_V1_0
server.send(200,"text/html", "Shutdown");
axp.shutdown();
#else
server.send(404,"text/html", "Not supported");
#endif
}
void handle_Restore() {
server.sendHeader("Location", "/");
server.send(302,"text/html", "");
@ -150,14 +169,16 @@ void handle_Cfg() {
jsonData += jsonLineFromPreferenceInt(PREF_DEV_AUTO_SHUT_PRESET);
jsonData += jsonLineFromInt("FreeHeap", ESP.getFreeHeap());
jsonData += jsonLineFromInt("HeapSize", ESP.getHeapSize());
jsonData += jsonLineFromInt("FreeSketchSpace", ESP.getFreeSketchSpace(), true);
jsonData += jsonLineFromInt("FreeSketchSpace", ESP.getFreeSketchSpace());
jsonData += jsonLineFromInt("PSRAMSize", ESP.getPsramSize());
jsonData += jsonLineFromInt("PSRAMFree", ESP.getFreePsram(), true);
jsonData += "}";
server.send(200,"application/json", jsonData);
}
void handle_ReceivedList() {
DynamicJsonDocument doc(MAX_RECEIVED_LIST_SIZE * 500);
PSRAMJsonDocument doc(MAX_RECEIVED_LIST_SIZE * 1000);
JsonObject root = doc.to<JsonObject>();
auto received = root.createNestedArray("received");
for (auto element: receivedPackets){
@ -234,6 +255,7 @@ void handle_saveDeviceCfg(){
server.on("/scan_wifi", handle_ScanWifi);
server.on("/save_wifi_cfg", handle_SaveWifiCfg);
server.on("/reboot", handle_Reboot);
server.on("/shutdown", handle_Shutdown);
server.on("/cfg", handle_Cfg);
server.on("/received_list", handle_ReceivedList);
server.on("/save_aprs_cfg", handle_SaveAPRSCfg);
@ -324,6 +346,7 @@ void handle_saveDeviceCfg(){
#ifdef KISS_PROTOCOL
tncServer.begin();
#endif
gpsServer.begin();
if (MDNS.begin(webServerCfg->callsign.c_str())) {
MDNS.setInstanceName(webServerCfg->callsign + " TTGO LoRa APRS TNC " + TXFREQ + "MHz");
MDNS.addService("http", "tcp", 80);

Wyświetl plik

@ -0,0 +1,64 @@
//
// Created by Admin on 11.06.2021.
//
#ifdef ENABLE_WIFI
#include <wifi_clients.h>
#include "wifi_clients.h"
void iterateWifiClients(f_connectedClientCallback_t callback, const String *data, WiFiClient * wifiClients[], int maxWifiClients){
for (int i=0; i < maxWifiClients; i++) {
auto client = wifiClients[i];
if (client != nullptr) {
if (client->connected()) {
callback(client, i, data);
} else {
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("Disconnected client ") + client->remoteIP().toString() + ":" + client->remotePort());
#endif
delete client;
wifiClients[i] = nullptr;
}
}
}
}
void check_for_new_clients(WiFiServer *wiFiServer, WiFiClient *wifiClients[], int maxWifiClients) {
WiFiClient new_client = wiFiServer->available();
if (new_client.connected()){
bool new_client_handled = false;
for (int i=0; i < maxWifiClients; i++) {
auto client = wifiClients[i];
if (client == nullptr) {
client = new WiFiClient(new_client);
wifiClients[i] = client;
new_client_handled = true;
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("New client #") +String(i) + ": " + client->remoteIP().toString() + ":" + client->remotePort());
#endif
break;
}
}
#ifdef ENABLE_WIFI_CLIENT_DEBUG
for (int i = 0; i < maxWifiClients; ++i) {
auto client = clients[i];
if (client != nullptr){
Serial.println(String("Client #") +String(i) + ": " + client->remoteIP().toString() + ":" + client->remotePort());
}
}
#endif
if (!new_client_handled){
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("Refusing client "));
#endif
new_client.stop();
}
}
}
#endif