Change in TNC Network clients handling
parent
3625b61697
commit
1e0fe1071e
|
@ -498,7 +498,7 @@ void setup(){
|
||||||
}
|
}
|
||||||
writedisplaytext("LoRa-APRS","","Init:","RF95 OK!","","",250);
|
writedisplaytext("LoRa-APRS","","Init:","RF95 OK!","","",250);
|
||||||
writedisplaytext(" "+Tcall,"","Init:","Waiting for GPS","","",250);
|
writedisplaytext(" "+Tcall,"","Init:","Waiting for GPS","","",250);
|
||||||
xTaskCreate(taskGPS, "taskGPS", 10000, nullptr, 1, nullptr);
|
xTaskCreate(taskGPS, "taskGPS", 5000, nullptr, 1, nullptr);
|
||||||
writedisplaytext(" "+Tcall,"","Init:","GPS Task Created!","","",250);
|
writedisplaytext(" "+Tcall,"","Init:","GPS Task Created!","","",250);
|
||||||
#ifndef T_BEAM_V1_0
|
#ifndef T_BEAM_V1_0
|
||||||
adc1_config_width(ADC_WIDTH_BIT_12);
|
adc1_config_width(ADC_WIDTH_BIT_12);
|
||||||
|
@ -523,7 +523,7 @@ void setup(){
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_WIFI
|
#ifdef ENABLE_WIFI
|
||||||
webServerCfg = {.callsign = Tcall};
|
webServerCfg = {.callsign = Tcall};
|
||||||
xTaskCreate(taskWebServer, "taskWebServer", 50000, (void*)(&webServerCfg), 1, nullptr);
|
xTaskCreate(taskWebServer, "taskWebServer", 40000, (void*)(&webServerCfg), 1, nullptr);
|
||||||
writedisplaytext("LoRa-APRS","","Init:","WiFi task started"," =:-) ","",250);
|
writedisplaytext("LoRa-APRS","","Init:","WiFi task started"," =:-) ","",250);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
//#define KISS_DEBUG
|
//#define KISS_DEBUG
|
||||||
#define ENABLE_WIFI
|
#define ENABLE_WIFI
|
||||||
#define NETWORK_TNC_PORT 8001
|
#define NETWORK_TNC_PORT 8001
|
||||||
|
//#define ENABLE_WIFI_CLIENT_DEBUG
|
||||||
|
|
||||||
|
|
||||||
#define MAX_TIME_TO_NEXT_TX 360000L // TRANSMIT INTERVAL set here MAXIMUM time in ms(!) for smart beaconing - minimum time is always 1 min = 60 secs = 60000L !!!
|
#define MAX_TIME_TO_NEXT_TX 360000L // TRANSMIT INTERVAL set here MAXIMUM time in ms(!) for smart beaconing - minimum time is always 1 min = 60 secs = 60000L !!!
|
||||||
#define FIX_BEACON_INTERVAL 1800000L // Fixed beacon interwal (when GPS is disabled and FIXED_BEACON_EN is enabled) 30min default
|
#define FIX_BEACON_INTERVAL 1800000L // Fixed beacon interwal (when GPS is disabled and FIXED_BEACON_EN is enabled) 30min default
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <list>
|
|
||||||
#include "taskTNC.h"
|
#include "taskTNC.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_BLUETOOTH
|
#ifdef ENABLE_BLUETOOTH
|
||||||
BluetoothSerial SerialBT;
|
BluetoothSerial SerialBT;
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,18 +8,24 @@ String inTNCData = "";
|
||||||
QueueHandle_t tncToSendQueue = nullptr;
|
QueueHandle_t tncToSendQueue = nullptr;
|
||||||
QueueHandle_t tncReceivedQueue = nullptr;
|
QueueHandle_t tncReceivedQueue = nullptr;
|
||||||
#ifdef ENABLE_WIFI
|
#ifdef ENABLE_WIFI
|
||||||
std::list<WiFiClient *> clientsList;
|
#define MAX_WIFI_CLIENTS 6
|
||||||
|
WiFiClient * clients[MAX_WIFI_CLIENTS];
|
||||||
|
|
||||||
typedef void (*f_connectedClientCallback_t) (WiFiClient *, const String *);
|
typedef void (*f_connectedClientCallback_t) (WiFiClient *, const String *);
|
||||||
|
|
||||||
void iterateWifiClients(std::list<WiFiClient *> clients, f_connectedClientCallback_t callback, const String *data){
|
void iterateWifiClients(f_connectedClientCallback_t callback, const String *data){
|
||||||
auto clientsIterator = clients.begin();
|
for (int i=0; i<MAX_WIFI_CLIENTS; i++) {
|
||||||
while (clientsIterator != clients.end()){
|
auto client = clients[i];
|
||||||
if ((*clientsIterator)->connected()){
|
if (client != nullptr) {
|
||||||
callback(*clientsIterator, data);
|
if (client->connected()) {
|
||||||
clientsIterator++;
|
callback(client, data);
|
||||||
} else {
|
} else {
|
||||||
clientsIterator = clients.erase(clientsIterator);
|
#ifdef ENABLE_WIFI_CLIENT_DEBUG
|
||||||
|
Serial.println(String("Disconnected client ") + client->remoteIP().toString() + ":" + client->remotePort());
|
||||||
|
#endif
|
||||||
|
delete client;
|
||||||
|
clients[i] = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +49,7 @@ void handleKISSData(char character) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_WIFI
|
#ifdef ENABLE_WIFI
|
||||||
iterateWifiClients(clientsList, [](WiFiClient *client, const String *data){
|
iterateWifiClients([](WiFiClient *client, const String *data){
|
||||||
if (client->connected()){
|
if (client->connected()){
|
||||||
client->print(*data);
|
client->print(*data);
|
||||||
client->flush();
|
client->flush();
|
||||||
|
@ -82,9 +88,38 @@ void handleKISSData(char character) {
|
||||||
#ifdef ENABLE_WIFI
|
#ifdef ENABLE_WIFI
|
||||||
WiFiClient new_client = tncServer.available();
|
WiFiClient new_client = tncServer.available();
|
||||||
if (new_client.connected()){
|
if (new_client.connected()){
|
||||||
clientsList.push_back(new WiFiClient(new_client));
|
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];
|
||||||
|
|
||||||
|
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(clientsList, [](WiFiClient * client, const String * unused){
|
iterateWifiClients([](WiFiClient * client, const String * unused){
|
||||||
while (client->available() > 0) {
|
while (client->available() > 0) {
|
||||||
char character = client->read();
|
char character = client->read();
|
||||||
handleKISSData(character);
|
handleKISSData(character);
|
||||||
|
@ -101,7 +136,7 @@ void handleKISSData(char character) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_WIFI
|
#ifdef ENABLE_WIFI
|
||||||
iterateWifiClients(clientsList, [](WiFiClient *client, const String *data){
|
iterateWifiClients([](WiFiClient *client, const String *data){
|
||||||
if (client->connected()){
|
if (client->connected()){
|
||||||
client->print(*data);
|
client->print(*data);
|
||||||
client->flush();
|
client->flush();
|
||||||
|
|
Loading…
Reference in New Issue