From 2959dfad4f6bf7943f3ec4c758be4989c5612f06 Mon Sep 17 00:00:00 2001
From: "Hans P. Reiser"
Date: Fri, 26 Apr 2019 23:09:09 +0200
Subject: [PATCH] background wifi scan/connected/reconnect. partial code,
incomplete, for testing station mode only (wifi=1)
---
RX_FSK/RX_FSK.ino | 878 ++++++++++++++++++++++-------------
libraries/SondeLib/Sonde.cpp | 4 +
libraries/SondeLib/Sonde.h | 1 +
3 files changed, 555 insertions(+), 328 deletions(-)
diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino
index 4fb310d..3a27250 100644
--- a/RX_FSK/RX_FSK.ino
+++ b/RX_FSK/RX_FSK.ino
@@ -14,7 +14,7 @@
#define LORA_LED 9
// UNCOMMENT one of the constructor lines below
-U8X8_SSD1306_128X64_NONAME_SW_I2C *u8x8=NULL; // initialize later after reading config file
+U8X8_SSD1306_128X64_NONAME_SW_I2C *u8x8 = NULL; // initialize later after reading config file
//U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ OLED_SCL, /* data=*/ OLED_SDA, /* reset=*/ OLED_RST); // Unbuffered, basic graphics, software I2C
//U8G2_SSD1306_128X64_NONAME_1_SW_I2C Display(U8G2_R0, /* clock=*/ OLED_SCL, /* data=*/ OLED_SDA, /* reset=*/ OLED_RST); // Page buffer, SW I2C
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C Display(U8G2_R0, /* clock=*/ OLED_SCL, /* data=*/ OLED_SDA, /* reset=*/ OLED_RST); // Full framebuffer, SW I2C
@@ -34,13 +34,13 @@ int ledPin = 1;
String ledState;
// Replaces placeholder with LED state value
-String processor(const String& var){
+String processor(const String& var) {
Serial.println(var);
- if(var == "STATE"){
- if(digitalRead(ledPin)){
+ if (var == "STATE") {
+ if (digitalRead(ledPin)) {
ledState = "ON";
}
- else{
+ else {
ledState = "OFF";
}
Serial.print(ledState);
@@ -53,14 +53,16 @@ String processor(const String& var){
const String sondeTypeSelect(int activeType) {
String sts = "";
- for(int i=0; i<3; i++) {
- sts += "";
+ for (int i = 0; i < 3; i++) {
+ sts += "";
}
return sts;
}
@@ -75,29 +77,35 @@ char message[10240];
void setupChannelList() {
File file = SPIFFS.open("/qrg.txt", "r");
- if(!file) {
+ if (!file) {
Serial.println("There was an error opening the file '/qrg.txt' for reading");
return;
}
- int i=0;
+ int i = 0;
sonde.clearSonde();
- Serial.println("Reading channel config:");
- while(file.available()) {
+ Serial.println("Reading channel config:");
+ while (file.available()) {
String line = file.readStringUntil('\n');
- if(!file.available()) break;
- if(line[0] == '#') continue;
+ if (!file.available()) break;
+ if (line[0] == '#') continue;
char *space = strchr(line.c_str(), ' ');
- if(!space) continue;
+ if (!space) continue;
*space = 0;
float freq = atof(line.c_str());
SondeType type;
- if(space[1]=='4') { type=STYPE_RS41; }
- else if (space[1]=='9') { type=STYPE_DFM09; }
- else if (space[1]=='6') { type=STYPE_DFM06; }
+ if (space[1] == '4') {
+ type = STYPE_RS41;
+ }
+ else if (space[1] == '9') {
+ type = STYPE_DFM09;
+ }
+ else if (space[1] == '6') {
+ type = STYPE_DFM06;
+ }
else continue;
- int active = space[3]=='+'?1:0;
+ int active = space[3] == '+' ? 1 : 0;
char *launchsite = strchr(line.c_str(), ' ');
- Serial.printf("Add %f - type %d (on/off: %d)- Site: \n",freq,type,active,launchsite);
+ Serial.printf("Add %f - type %d (on/off: %d)- Site: \n", freq, type, active, launchsite);
sonde.addSonde(freq, type, active, launchsite);
i++;
}
@@ -105,19 +113,19 @@ void setupChannelList() {
const char *createQRGForm() {
char *ptr = message;
- strcpy(ptr,"");
- return message;
+ strcpy(ptr, "");
+ return message;
}
const char *handleQRGPost(AsyncWebServerRequest *request) {
@@ -125,7 +133,7 @@ const char *handleQRGPost(AsyncWebServerRequest *request) {
// parameters: a_i, f_1, t_i (active/frequency/type)
#if 1
File f = SPIFFS.open("/qrg.txt", "w");
- if(!f) {
+ if (!f) {
Serial.println("Error while opening '/qrg.txt' for writing");
return "Error while opening '/qrg.txt' for writing";
}
@@ -133,29 +141,29 @@ const char *handleQRGPost(AsyncWebServerRequest *request) {
Serial.println("Handling post request");
#if 0
int params = request->params();
- for(int i=0; igetParam(i)->name().c_str());
}
#endif
- for(int i=1; i<=MAX_QRG; i++) {
+ for (int i = 1; i <= MAX_QRG; i++) {
snprintf(label, 10, "A%d", i);
AsyncWebParameter *active = request->getParam(label, true);
snprintf(label, 10, "F%d", i);
AsyncWebParameter *freq = request->getParam(label, true);
- if(!freq) continue;
+ if (!freq) continue;
snprintf(label, 10, "T%d", i);
AsyncWebParameter *type = request->getParam(label, true);
- if(!type) continue;
+ if (!type) continue;
const char *fstr = freq->value().c_str();
const char *tstr = type->value().c_str();
- Serial.printf("Processing a=%s, f=%s, t=%s\n", active?"YES":"NO", fstr, tstr);
- char typech = (tstr[2]=='4'?'4':tstr[3]); // Ugly TODO
- f.printf("%3.3f %c %c\n", atof(fstr), typech, active?'+':'-');
+ Serial.printf("Processing a=%s, f=%s, t=%s\n", active ? "YES" : "NO", fstr, tstr);
+ char typech = (tstr[2] == '4' ? '4' : tstr[3]); // Ugly TODO
+ f.printf("%3.3f %c %c\n", atof(fstr), typech, active ? '+' : '-');
}
f.close();
Serial.println("Channel setup finished");
Serial.println();
-
+
setupChannelList();
}
@@ -164,45 +172,52 @@ const char *handleQRGPost(AsyncWebServerRequest *request) {
#define MAX_WIFI 10
int nNetworks;
-struct { String id; String pw; } networks[MAX_WIFI];
+struct {
+ String id;
+ String pw;
+} networks[MAX_WIFI];
// FIXME: For now, we don't uspport wifi networks that contain newline or null characters
// ... would require a more sophisicated file format (currently one line SSID; one line Password
void setupWifiList() {
File file = SPIFFS.open("/networks.txt", "r");
- if(!file){
+ if (!file) {
Serial.println("There was an error opening the file '/networks.txt' for reading");
return;
}
- int i=0;
-
- while(file.available()) {
+ int i = 0;
+
+ while (file.available()) {
String line = file.readStringUntil('\n');
- if(!file.available()) break;
- networks[i].id = line;
- networks[i].pw = file.readStringUntil('\n');
- i++;
+ if (!file.available()) break;
+ networks[i].id = line;
+ networks[i].pw = file.readStringUntil('\n');
+ i++;
}
nNetworks = i;
Serial.print(i); Serial.println(" networks in networks.txt\n");
- for(int j=0; j