From 16aae406b24825f9a51217410eb46fd7c270c9cb Mon Sep 17 00:00:00 2001 From: Sottosistema W10 Date: Thu, 16 Sep 2021 19:54:14 +0200 Subject: [PATCH] Added configurable AP password as in #51. Improved battery reading on T-Beam 0.7 as in #65. Fixed AP detection in serial printing. Updated readme.md --- README.md | 3 ++- data_embed/index.html | 6 +++--- include/preference_storage.h | 1 + src/TTGO_T-Beam_LoRa_APRS.ino | 4 ++-- src/taskWebServer.cpp | 37 +++++++++++++++++++++++++++++------ 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5eb5393..535852a 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,14 @@ After connection with APRX based DIGI it can be used as KISS-TNC * In the left column click on the ANT-shaped icon, choose your board and click on "Upload". COM port should be detected automatically Wait for procedure to finish and keep reading ## Configuring parameters -Wait for the board to reboot, connect to "N0CALL AP" WiFi network, password is: xxxxxxxxxx (10 times "x") and point your browser to "192.168.4.1" +Wait for the board to reboot, connect to "N0CALL AP" WiFi network, password is: xxxxxxxxxx (10 times "x") and point your browser to "192.168.4.1". Hover your mouse to textboxes to get useful hints. ### WiFi Settings you can scan for local SSID or manually type in name and password * Scan WiFi: scan for local WiFi networks * SSID: name of the AP to connect to * Password: password of WiFi AP +* AUTO AP Password: if configured network is not reachable the AP mode will be enabled, SSID will be your callsign and this will be the password ### APRS Settings These are main APRS settings such as callsign, SSID and symbol (refer to: http://www.aprs.org/symbols.html). Please remember to turn ON GPS in order to use it as a tracker. diff --git a/data_embed/index.html b/data_embed/index.html index 0ca51c3..6e94212 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -26,15 +26,15 @@
- +
- +
- +
diff --git a/include/preference_storage.h b/include/preference_storage.h index fc883be..084f0ac 100644 --- a/include/preference_storage.h +++ b/include/preference_storage.h @@ -9,6 +9,7 @@ extern Preferences preferences; // MAX 15 chars for preferenece key!!! static const char *const PREF_WIFI_SSID = "wifi_ssid"; static const char *const PREF_WIFI_PASSWORD = "wifi_password"; +static const char *const PREF_AP_PASSWORD = "ap_password"; // LoRa settings static const char *const PREF_LORA_FREQ_PRESET_INIT = "lora_freq_i"; static const char *const PREF_LORA_FREQ_PRESET = "lora_freq"; diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index eb3a5c2..6508baa 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -366,9 +366,9 @@ void batt_read(){ BattVolts = axp.getBattVoltage()/1000; InpVolts = axp.getVbusVoltage()/1000; #elif T_BEAM_V0_7 - BattVolts = ((float)analogRead(35) / 8192.0) * 2.0 * 3.3 * (1100.0 / 1000.0); // fixed thanks to Luca IU2FRL + BattVolts = (((float)analogRead(35) / 8192.0) * 2.0 * 3.3 * (1100.0 / 1000.0))+0.41; // fixed thanks to Luca IU2FRL #else - BattVolts = analogRead(35)*7.221/4096; // fixed thanks to Luca IU2FRL + BattVolts = analogRead(35)*7.221/4096; #endif } diff --git a/src/taskWebServer.cpp b/src/taskWebServer.cpp index 1f0b987..39b6f79 100644 --- a/src/taskWebServer.cpp +++ b/src/taskWebServer.cpp @@ -112,15 +112,26 @@ void handle_ScanWifi() { } void handle_SaveWifiCfg() { - if (!server.hasArg(PREF_WIFI_SSID) || !server.hasArg(PREF_WIFI_PASSWORD)){ - server.send(500, "text/plain", "Invalid request"); + if (!server.hasArg(PREF_WIFI_SSID) || !server.hasArg(PREF_WIFI_PASSWORD) || !server.hasArg(PREF_AP_PASSWORD)){ + server.send(500, "text/plain", "Invalid request, make sure all fields are set"); } if (!server.arg(PREF_WIFI_SSID).length()){ - server.send(403, "text/plain", "Empty SSID or Password"); + server.send(403, "text/plain", "Empty SSID"); + } + if (server.arg(PREF_WIFI_PASSWORD)!="*" && server.arg(PREF_AP_PASSWORD).length()<8){ + server.send(403, "text/plain", "WiFi Password must be minimum 8 character"); + } + if (server.arg(PREF_AP_PASSWORD)!="*" && server.arg(PREF_AP_PASSWORD).length()<8){ + server.send(403, "text/plain", "AP Password must be minimum 8 character"); } preferences.putString(PREF_WIFI_SSID, server.arg(PREF_WIFI_SSID)); - preferences.putString(PREF_WIFI_PASSWORD, server.arg(PREF_WIFI_PASSWORD)); + if (server.arg(PREF_WIFI_PASSWORD)!="*") { + preferences.putString(PREF_WIFI_PASSWORD, server.arg(PREF_WIFI_PASSWORD)); + } + if (server.arg(PREF_AP_PASSWORD)!="*") { + preferences.putString(PREF_AP_PASSWORD, server.arg(PREF_AP_PASSWORD)); + } server.sendHeader("Location", "/"); server.send(302,"text/html", ""); @@ -159,6 +170,7 @@ void handle_Restore() { void handle_Cfg() { String jsonData = "{"; jsonData += String("\"") + PREF_WIFI_PASSWORD + "\": \"" + jsonEscape((preferences.getString(PREF_WIFI_PASSWORD).isEmpty() ? String("") : "*")) + R"(",)"; + jsonData += String("\"") + PREF_AP_PASSWORD + "\": \"" + jsonEscape((preferences.getString(PREF_AP_PASSWORD).isEmpty() ? String("") : "*")) + R"(",)"; jsonData += jsonLineFromPreferenceString(PREF_WIFI_SSID); jsonData += jsonLineFromPreferenceDouble(PREF_LORA_FREQ_PRESET); jsonData += jsonLineFromPreferenceInt(PREF_LORA_SPEED_PRESET); @@ -346,6 +358,10 @@ void handle_saveDeviceCfg(){ String wifi_password = preferences.getString(PREF_WIFI_PASSWORD); String wifi_ssid = preferences.getString(PREF_WIFI_SSID); + if (preferences.getString(PREF_AP_PASSWORD).length() > 8) { + // 8 characters is requirements for WPA2 + apPassword = preferences.getString(PREF_AP_PASSWORD); + } if (!wifi_ssid.length()){ WiFi.softAP(apSSID.c_str(), apPassword.c_str()); } else { @@ -361,15 +377,24 @@ void handle_saveDeviceCfg(){ retryWifi += 1; if (retryWifi > 60) { WiFi.softAP(apSSID.c_str(), apPassword.c_str()); + //WiFi.softAP(apSSID.c_str(), "password"); Serial.println("Unable to connect to to wifi. Starting AP"); + Serial.print("SSID: "); + Serial.print(apSSID.c_str()); + Serial.print(" Password: "); + Serial.println(apPassword.c_str()); break; } } - if (WiFi.getMode() == wifi_mode_t::WIFI_MODE_AP){ + //Serial.print("WiFi Mode: "); + //Serial.println(WiFi.getMode()); + if (WiFi.getMode() == 3){ Serial.println("Running AP. IP: " + WiFi.softAPIP().toString()); - } else { + } else if (WiFi.getMode() == 1) { Serial.println("Connected. IP: " + WiFi.localIP().toString()); + } else { + Serial.println("WiFi Mode: " + WiFi.getMode()); } #ifdef ENABLE_SYSLOG