From 3f0a946d49889a176ece43211ef90c9783f9f820 Mon Sep 17 00:00:00 2001 From: Atten Date: Mon, 24 Jan 2022 22:14:51 +0700 Subject: [PATCH] Add WiFi AP Config and edit bug Update Firmware has fail. --- include/webservice.h | 3 +- src/main.cpp | 4 +- src/webservice.cpp | 91 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 90 insertions(+), 8 deletions(-) diff --git a/include/webservice.h b/include/webservice.h index 7a21a1b..cc9291e 100644 --- a/include/webservice.h +++ b/include/webservice.h @@ -12,8 +12,7 @@ extern statusType status; extern digiTLMType digiTLM; extern Configuration config; extern TaskHandle_t taskNetworkHandle; -extern TaskHandle_t taskDSPHandle; -extern TaskHandle_t taskUIHandle; +extern TaskHandle_t taskAPRSHandle; extern time_t systemUptime; extern pkgListType pkgList[PKGLISTSIZE]; diff --git a/src/main.cpp b/src/main.cpp index 25d6961..e92626e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -481,7 +481,7 @@ void setup() xTaskCreatePinnedToCore( taskAPRS, /* Function to implement the task */ "taskAPRS", /* Name of the task */ - 8192, /* Stack size in words */ + 16384, /* Stack size in words */ NULL, /* Task input parameter */ 1, /* Priority of the task */ &taskAPRSHandle, /* Task handle. */ @@ -623,6 +623,7 @@ void taskAPRS(void *pvParameters) time_t timeStamp; time(&timeStamp); vTaskDelay(10 / portTICK_PERIOD_MS); + //serviceHandle(); if (digitalRead(0) == LOW) { @@ -836,6 +837,7 @@ void taskNetwork(void *pvParameters) // wdtNetworkTimer = millis(); vTaskDelay(1 / portTICK_PERIOD_MS); serviceHandle(); + if (config.wifi_mode == WIFI_AP_STA_FIX || config.wifi_mode == WIFI_STA_FIX) { if (WiFi.status() != WL_CONNECTED) diff --git a/src/webservice.cpp b/src/webservice.cpp index 7834e0f..d6a53f6 100644 --- a/src/webservice.cpp +++ b/src/webservice.cpp @@ -483,7 +483,7 @@ void handle_setting() } } } - + config.synctime = synctime; saveEEPROM(); // topBar(WiFi.RSSI()); @@ -847,6 +847,7 @@ void handle_system() break; } } + saveEEPROM(); } else if (server.hasArg("updateTime")) { @@ -906,11 +907,71 @@ void handle_system() break; } } + saveEEPROM(); } else if (server.hasArg("updateWifi")) { + bool wifiSTA = false; + bool wifiAP = false; for (uint8_t i = 0; i < server.args(); i++) { + if (server.argName(i) == "wifiAP") + { + if (server.arg(i) != "") + { + if (String(server.arg(i)) == "OK") + { + wifiAP = true; + } + } + } + if (server.argName(i) == "wificlient") + { + if (server.arg(i) != "") + { + if (String(server.arg(i)) == "OK") + { + wifiSTA = true; + } + } + } + + if (server.argName(i) == "gpsLat") + { + if (server.arg(i) != "") + { + config.gps_lat = server.arg(i).toFloat(); + } + } + if (server.argName(i) == "gpsLon") + { + if (server.arg(i) != "") + { + config.gps_lon = server.arg(i).toFloat(); + } + } + if (server.argName(i) == "gpsAlt") + { + if (server.arg(i) != "") + { + config.gps_alt = server.arg(i).toFloat(); + } + } + + if (server.argName(i) == "wifi_ssidAP") + { + if (server.arg(i) != "") + { + strcpy(config.wifi_ap_ssid, server.arg(i).c_str()); + } + } + if (server.argName(i) == "wifi_passAP") + { + if (server.arg(i) != "") + { + strcpy(config.wifi_ap_pass, server.arg(i).c_str()); + } + } if (server.argName(i) == "wifi_ssid") { if (server.arg(i) != "") @@ -926,6 +987,23 @@ void handle_system() } } } + if (wifiAP && wifiSTA) + { + config.wifi_mode = WIFI_AP_STA_FIX; + } + else if (wifiAP) + { + config.wifi_mode = WIFI_AP_FIX; + } + else if (wifiSTA) + { + config.wifi_mode = WIFI_STA_FIX; + } + else + { + config.wifi_mode = WIFI_OFF_FIX; + } + saveEEPROM(); } struct tm tmstruct; @@ -987,7 +1065,7 @@ void handle_system() webString += "\n"; webString += "
\n"; webString += "
\n"; - + webString += "
\n"; webString += "\n"; String wifiFlage = ""; @@ -1324,7 +1402,7 @@ void webService() HTTPUpload &upload = server.upload(); if (upload.status == UPLOAD_FILE_START) { - // Serial.printf("Firmware Update FILE: %s\n", upload.filename.c_str()); + Serial.printf("Firmware Update FILE: %s\n", upload.filename.c_str()); if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { // start with max available size Update.printError(Serial); @@ -1334,9 +1412,12 @@ void webService() { // wdtDisplayTimer = millis(); // wdtSensorTimer = millis(); - // vTaskSuspend(taskSensorHandle); - vTaskSuspend(taskNetworkHandle); + i2s_adc_disable(I2S_NUM_0); + dac_i2s_disable(); + vTaskSuspend(taskAPRSHandle); + //vTaskSuspend(taskNetworkHandle); config.aprs = false; + config.tnc=false; #ifndef I2S_INTERNAL AFSK_TimerEnable(false); #endif