diff --git a/include/TEF6686.h b/include/TEF6686.h index 05a6e28..9be0f83 100644 --- a/include/TEF6686.h +++ b/include/TEF6686.h @@ -100,7 +100,7 @@ static const uint16_t oda_app_ids[] { static const char* const ECCtext[] { "Bundesrepublik Deutschland", // 0 - "Ελληνική Δημοκρατία / (Hellenic Republic)", // 1 + "Ελληνική Δημοκρατία [Hellenic Republic]", // 1 "Kingdom of Morroco", // 2 "Republica Moldova", // 3 "People's Democratic Republic of Algeria", // 4 @@ -297,8 +297,8 @@ static const char* const ECCtext[] { "Islamic Republic of Iran", // 195 "Japan", // 196 "Republic of Kiribati", // 197 - "Democratic People's Republic of Korea (North Korea)", // 198 - "Republic of Korea (South Korea)", // 199 + "Democratic People's Republic of Korea [North Korea]", // 198 + "Republic of Korea [South Korea]", // 199 "Lao People's Democratic Republic", // 200 "中华人民共和国(澳门) [PRC, M]", // 201 "Malaysia", // 202 @@ -316,7 +316,7 @@ static const char* const ECCtext[] { "Republic of Singapore", // 214 "Solomon Islands", // 215 "Democratic Socialist Republic of Sri Lanka", // 216 - "Republic of China (Taiwan)", // 217 + "Republic of China [Taiwan]", // 217 "Kingdom of Thailand", // 218 "Kingdom of Tonga", // 219 "Republic of Vanuatu", // 220 diff --git a/include/constants.h b/include/constants.h index 139287c..d43151c 100644 --- a/include/constants.h +++ b/include/constants.h @@ -265,17 +265,17 @@ #define ITEM10 210 // EEPROM index defines -#define EE_PRESETS_CNT 99 // When set > 99 change the complete EEPROM adressing! -#define EE_CHECKBYTE_VALUE 20 // 0 ~ 255,add new entry, change for new value -#define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped! -#define EE_TOTAL_CNT 2287 // Total occupied eeprom bytes +#define EE_PRESETS_CNT 99 // When set > 99 change the complete EEPROM adressing! +#define EE_CHECKBYTE_VALUE 20 // 0 ~ 255,add new entry, change for new value +#define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped! +#define EE_TOTAL_CNT 2287 // Total occupied eeprom bytes -#define EE_PRESETS_BAND_START 0 // 99 * 1 byte -#define EE_PRESET_BW_START 99 // 99 * 1 byte -#define EE_PRESET_MS_START 198 // 99 * 1 byte -#define EE_PRESETS_FREQUENCY_START 297 // 99 * 4 bytes -#define EE_PRESETS_RDSPI_START 693 // 99 * 5 bytes -#define EE_PRESETS_RDSPS_START 1188 // 99 * 9 bytes +#define EE_PRESETS_BAND_START 0 // 99 * 1 byte +#define EE_PRESET_BW_START 99 // 99 * 1 byte +#define EE_PRESET_MS_START 198 // 99 * 1 byte +#define EE_PRESETS_FREQUENCY_START 297 // 99 * 4 bytes +#define EE_PRESETS_RDSPI_START 693 // 99 * 5 bytes +#define EE_PRESETS_RDSPS_START 1188 // 99 * 9 bytes #define EE_UINT16_FREQUENCY_FM 2079 #define EE_BYTE_VOLSET 2083 @@ -356,40 +356,40 @@ #define EE_BYTE_FMSCANSENS 2201 #define EE_BYTE_FREQFONT 2202 // Empty space, this was not used -#define EE_BYTE_XDRGTKMUTE 2204 -#define EE_BYTE_FMAGC 2205 -#define EE_BYTE_AMAGC 2206 -#define EE_BYTE_FMSI 2207 -#define EE_BYTE_SCANSTART 2208 -#define EE_BYTE_SCANSTOP 2209 -#define EE_BYTE_SCANHOLD 2210 -#define EE_BYTE_SCANMEM 2211 -#define EE_BYTE_SCANCANCEL 2212 -#define EE_BYTE_SCANMUTE 2213 -#define EE_BYTE_AUTOSQUELCH 2214 -#define EE_BYTE_LONGBANDPRESS 2215 -#define EE_BYTE_SHOWCLOCK 2216 -#define EE_BYTE_SHOWLONGPS 2217 -#define EE_UINT16_MEMSTARTFREQ 2218 -#define EE_UINT16_MEMSTOPFREQ 2222 -#define EE_BYTE_MEMSTARTPOS 2226 -#define EE_BYTE_MEMSTOPPOS 2227 -#define EE_BYTE_MEMPIONLY 2228 -#define EE_BYTE_MEMDOUBLEPI 2229 +#define EE_BYTE_XDRGTKMUTE 2204 +#define EE_BYTE_FMAGC 2205 +#define EE_BYTE_AMAGC 2206 +#define EE_BYTE_FMSI 2207 +#define EE_BYTE_SCANSTART 2208 +#define EE_BYTE_SCANSTOP 2209 +#define EE_BYTE_SCANHOLD 2210 +#define EE_BYTE_SCANMEM 2211 +#define EE_BYTE_SCANCANCEL 2212 +#define EE_BYTE_SCANMUTE 2213 +#define EE_BYTE_AUTOSQUELCH 2214 +#define EE_BYTE_LONGBANDPRESS 2215 +#define EE_BYTE_SHOWCLOCK 2216 +#define EE_BYTE_SHOWLONGPS 2217 +#define EE_UINT16_MEMSTARTFREQ 2218 +#define EE_UINT16_MEMSTOPFREQ 2222 +#define EE_BYTE_MEMSTARTPOS 2226 +#define EE_BYTE_MEMSTOPPOS 2227 +#define EE_BYTE_MEMPIONLY 2228 +#define EE_BYTE_MEMDOUBLEPI 2229 // blank space -#define EE_BYTE_WAITONLYONSIGNAL 2253 -#define EE_UINT16_CALTOUCH1 2254 -#define EE_UINT16_CALTOUCH2 2258 -#define EE_UINT16_CALTOUCH3 2262 -#define EE_UINT16_CALTOUCH4 2266 -#define EE_UINT16_CALTOUCH5 2270 -#define EE_BYTE_INVERTDISPLAY 2274 -#define EE_BYTE_NTPOFFSET 2275 -#define EE_BYTE_AUTOLOG 2276 -#define EE_BYTE_AUTODST 2277 -#define EE_BYTE_CLOCKAMPM 2278 -#define EE_UINT16_LOGCOUNTER 2279 -#define EE_UINT16_PICTLOCK 2283 +#define EE_BYTE_WAITONLYONSIGNAL 2253 +#define EE_UINT16_CALTOUCH1 2254 +#define EE_UINT16_CALTOUCH2 2258 +#define EE_UINT16_CALTOUCH3 2262 +#define EE_UINT16_CALTOUCH4 2266 +#define EE_UINT16_CALTOUCH5 2270 +#define EE_BYTE_INVERTDISPLAY 2274 +#define EE_BYTE_TIMEZONE 2275 +#define EE_BYTE_AUTOLOG 2276 +#define EE_BYTE_AUTODST 2277 +#define EE_BYTE_CLOCKAMPM 2278 +#define EE_UINT16_LOGCOUNTER 2279 +#define EE_UINT16_PICTLOCK 2283 // End of EEPROM index defines // Memory channel database diff --git a/include/globals.h b/include/globals.h index 3ef294b..b57c892 100644 --- a/include/globals.h +++ b/include/globals.h @@ -229,7 +229,7 @@ extern int8_t MPold; extern int8_t USold; extern int8_t LevelOffset; extern int8_t LowLevelSet; -extern int8_t NTPoffset; +extern int8_t Timezone; extern int8_t CN; extern int8_t CNold; extern int8_t VolSet; diff --git a/include/language.h b/include/language.h index 5b8c83d..6ed7c75 100644 --- a/include/language.h +++ b/include/language.h @@ -319,7 +319,7 @@ static const char* const Languages[22][297] PROGMEM = { "Can't add entry!\nLogbook is full!", // 291 "Autologger", // 292 "Auto DST on NTP time", // 293 - "Set NTP time offset", // 294 + "Set time zone", // 294 "The logbook contains over 130 entries, which the viewer cannot process. Please download the CSV file to process it.", // 295 "Canada" // 296 }, @@ -618,7 +618,7 @@ static const char* const Languages[22][297] PROGMEM = { "Toevoegen mislukt!\nLogboek is vol!", // 291 "Automatisch loggen", // 292 "Auto zomertijd\nop NTP tijd", // 293 - "NTP tijdverschil\ninstellen", // 294 + "Tijdzone", // 294 "Het logboek bevat meer dan 130 items, die de viewer niet kan verwerken. Download alstublieft het CSV-bestand om het te bekijken.", // 295 "Canada" // 296 }, @@ -917,7 +917,7 @@ static const char* const Languages[22][297] PROGMEM = { "Wykaz pełny!", // 291 "Autologowanie stacji", // 292 "Auto czas letni wg NTP", // 293 - "Ustaw odchyl. czasu NTP", // 294 + "Strefa czasowa", // 294 "Wykaz zawiera ponad 130 wpisów, których przeglądarka nie może pokazać. Pobierz plik CSV, aby je przetworzyć.", // 295 "Kanada" // 296 }, @@ -1216,7 +1216,7 @@ static const char* const Languages[22][297] PROGMEM = { "Ne mogu dodati unos!\nDnevnik je pun!", // 291 "Autologger", // 292 "Auto DST na NTP vremenu", // 293 - "Postavi NTP pomak vremena", // 294 + "postaviti pomak vremenske zone", // 294 "Dnevnik sadrži preko 130 unosa, koje preglednik ne može obraditi. Preuzmite CSV datoteku za obradu.", // 295 "Canada" // 296 }, @@ -1515,7 +1515,7 @@ static const char* const Languages[22][297] PROGMEM = { "Αδυναμία προσθήκης!\nΒιβλίο γεμάτο!", // 291 "Αυτόματη καταγραφή", // 292 "Αυτόματο DST\nσε ώρα NTP", // 293 - "Ολίσθηση ώρας NTP", // 294 + "Ορισμός ζώνης ώρας", // 294 "Το βιβλίο περιέχει πάνω από 130 καταγραφές, και είναι αδύνατη η επεξεργασία τους από το χρήστη. Κάντε λήψη του αρχείου CSV για να το επεξεργαστείτε.", // 295 "Καναδάς" // 296 }, @@ -1814,7 +1814,7 @@ static const char* const Languages[22][297] PROGMEM = { "Nu se poate adăuga!\nJurnalul este plin!", // 291 "Autologger", // 292 "Auto DST pe ora NTP", // 293 - "Setează offsetul pentru ora NTP", // 294 + "Setați fusul orar", // 294 "Jurnalul conține peste 130 de intrări, pe care vizualizatorul nu le poate procesa. Te rog descarcă fișierul CSV pentru a le procesa.", // 295 "Canada" // 296 }, @@ -2113,7 +2113,7 @@ static const char* const Languages[22][297] PROGMEM = { "Logbucheintrag nicht möglich\nLogbuch ist voll!", // 291 "Automatisch loggen", // 292 "Auto-Sommerzeit\nüber NTP", // 293 - "NTP-Zeitversatz\neinstellen", // 294 + "Zeitzone einstellen", // 294 "Das Logbuch enthält mehr als 130 Einträge, was das Anzeigeprogramm nicht verarbeiten kann. Bitte lade die CSV-Datei zum Verarbeiten herunter.", // 295 "Kanada" // 296 }, @@ -2412,7 +2412,7 @@ static const char* const Languages[22][297] PROGMEM = { "Nelze přidat položku!\nLogbook je plný!", // 291 "Automatický logger", // 292 "Auto DST u NTP času", // 293 - "Nastavte časový posun NTP", // 294 + "Nastavit časové pásmo", // 294 "Logbook obsahuje více než 130 položek, které prohlížeč nedokáže zpracovat. Pro zpracování všech položek si stáhněte CSV soubor.", // 295 "Canada" // 296 }, @@ -2711,7 +2711,7 @@ static const char* const Languages[22][297] PROGMEM = { "Nem adható hozzá!\nLogbook megtelt!", // 291 "Auto logoló", // 292 "Auto nyári idő(DST)\nNTP idő szerint", // 293 - "NTP időeltolás beállítása", // 294 + "Állítsa be az időzónát", // 294 "A napló több mint 130 bejegyzést tartalmaz, amelyeket a megtekintő nem tud feldolgozni. Kérlek, töltsd le a CSV fájlt a megtekintéshez.", // 295 "Kanada" // 296 }, @@ -3010,7 +3010,7 @@ static const char* const Languages[22][297] PROGMEM = { "Impossible d'ajouter l'entrée!\nJournal de bord plein!", // 291 "Log automatique", // 292 "DST automatique\nsur l'heure NTP", // 293 - "Décalage horaire NTP", // 294 + "Définir le fuseau horaire", // 294 "Le journal de bord contient plus de 130 entrées que la liste ne peut pas afficher. Veuillez télécharger le fichier CSV.", // 295 "Canada" // 296 }, @@ -3309,7 +3309,7 @@ static const char* const Languages[22][297] PROGMEM = { "Не може да се добави запис!\nДневникът е пълен!", // 291 "Автоматичен дневник", // 292 "Автоматично лятно\nвреме по NTP", // 293 - "Отместване на NTP", // 294 + "Задаване на часова зона", // 294 "Дневникът съдържа над 130 записа, които не могат да бъдат обработени. Моля, изтеглете CSV файла за обработка.", // 295 "Канада" // 296 }, @@ -3608,7 +3608,7 @@ static const char* const Languages[22][297] PROGMEM = { "Смещение времени NTP", // 291 "Автологгер", // 292 "Автоматическое летнее время по NTP", // 293 - "Смещение времени NTP", // 294 + "Установить часовой пояс", // 294 "В логе более 130 записей, которые программа просмотра не может обработать. Загрузите файл CSV для его обработки.", // 295 "Канада" // 296 }, @@ -3907,7 +3907,7 @@ static const char* const Languages[22][297] PROGMEM = { "Твій журнал повний!", // 291 "Автореєстратор", // 292 "Автоматичний літній\nчас за NTP", // 293 - "Встановити зміщення\nчасу NTP", // 294 + "Встановити часовий пояс", // 294 "Журнал містить понад 130 записів, які оглядач не може обробити. Будь ласка, завантажте файл CSV, щоб обробити його.", // 295 "Канада" // 296 }, @@ -4206,7 +4206,7 @@ static const char* const Languages[22][297] PROGMEM = { "Impossibile aggiungere voce!\nRegistro dei log pieno!", // 291 "Autologger", // 292 "Auto DST su tempo NTP", // 293 - "Imposta offset orario NTP", // 294 + "Imposta il fuso orario", // 294 "Registro dei log con + di 130 voci, il visualizzatore non può gestirle. Scarica il file CSV per gestirlo.", // 295 "Canada" // 296 }, @@ -4505,7 +4505,7 @@ static const char* const Languages[22][297] PROGMEM = { "log记录已满!", // 291 "自动记录日志", // 292 "联网自动同步本机时间", // 293 - "设置NTP时区", // 294 + "设置时区", // 294 "该日志包含超过130个条目,观看者无法处理。请下载CSV文件进行处理。", // 295 "加拿大" // 296 }, @@ -4804,7 +4804,7 @@ static const char* const Languages[22][297] PROGMEM = { "Kan ikke lagre!\nLoggbok er full!", // 291 "Autologger", // 292 "Auto sommertid med NTP", // 293 - "Angi NTP-tidsforskyvning", // 294 + "Angi tidssone", // 294 "Loggbok har over 130 oppføringer.\nLast ned CSV for behandling.", // 295 "Canada" // 296 }, @@ -5103,7 +5103,7 @@ static const char* const Languages[22][297] PROGMEM = { "¡Registro lleno!\nNo se puede añadir", // 291 "Autoregistro", // 292 "DST automático (NTP)", // 293 - "Ajustar\ndesplazamiento NTP", // 294 + "Establecer zona horaria", // 294 "El registro tiene +130 entradas.\nDescargue el CSV.", // 295 "Canadá" // 296 }, @@ -5402,7 +5402,7 @@ static const char* const Languages[22][297] PROGMEM = { "Não é possível adicionar!\nO livro está cheio!", // 291 "Registrador automático", // 292 "DST automático\nno horário NTP", // 293 - "Definir deslocamento\nde tempo NTP", // 294 + "Definir fuso horário", // 294 "O diário de bordo contém mais de 130 entradas que o espectador não consegue processar. Descarregue o ficheiro CSV para processá-lo.", // 295 "Canadá" // 296 }, @@ -5701,7 +5701,7 @@ static const char* const Languages[22][297] PROGMEM = { "Ne može se dodati!\nDnevnik je pun!", // 291 "Automatski logger", // 292 "Auto DST na\nNTP vremenu", // 293 - "Postavite NTP\nvremenski offset", // 294 + "Podesite vremensku zonu", // 294 "Dnevnik sadrži više od 130 unosa, što viewer ne može obraditi. Preuzmite CSV fajl za obradu.", // 295 "Canada" // 296 }, @@ -6000,7 +6000,7 @@ static const char* const Languages[22][297] PROGMEM = { "Ei voida lisätä merkintää!\nLokikirja on täynnä!", // 291 "Autolokikirja", // 292 "Auto DST\nNTP-ajassa", // 293 - "Aseta\nNTP-aikasiirto", // 294 + "Aseta aikavyöhyke", // 294 "Lokikirja sisältää yli 130 merkintää, joita katselija ei pysty käsittelemään. Lataa CSV-tiedosto sen käsittelemiseksi.", // 295 "Kanada" // 296 }, @@ -6299,7 +6299,7 @@ static const char* const Languages[22][297] PROGMEM = { "Kan ikke tilføje!\nLogbogen er fuld!", // 291 "Autologger", // 292 "Auto DST på\nNTP-tid", // 293 - "Indstil NTP-tidsforskel", // 294 + "Indstil tidszone", // 294 "Logbogen indeholder over 130 poster, som fremviseren ikke kan behandle. Download CSV-filen for at behandle den.", // 295 "Canada" // 296 }, @@ -6598,7 +6598,7 @@ static const char* const Languages[22][297] PROGMEM = { "Kan inte spara!\nLoggboken är full!", // 291 "Autologgning", // 292 "Auto NTP sommartid", // 293 - "Ange NTP tidszon", // 294 + "Ställ in tidszon", // 294 "Loggboken har mer än 130 poster, vilket visaren inte kan hantera. Ladda ner CSV för behandling.", // 295 "Kanada" // 296 } diff --git a/include/rtc.hpp b/include/rtc.hpp index cc624d4..b83d811 100644 --- a/include/rtc.hpp +++ b/include/rtc.hpp @@ -12,4 +12,4 @@ extern ESP32Time rtc; extern bool rx_rtc_avail; bool init_rtc(); -void set_time(time_t time); \ No newline at end of file +void set_time(time_t time, int8_t offset); \ No newline at end of file diff --git a/include/touch.h b/include/touch.h index 1bc5706..2889cd7 100644 --- a/include/touch.h +++ b/include/touch.h @@ -1,28 +1,22 @@ #pragma once #include "globals.h" +#include "core.h" void doTouchEvent(uint16_t x, uint16_t y); extern void BuildDisplay(); extern void BuildBWSelector(); -extern void SelectBand(); extern void BuildAdvancedRDS(); extern void doBandToggle(); extern void doTuneMode(); -extern void doStereoToggle(); -extern void cancelDXScan(); -extern void doBW(); extern void drawButton(const char* text, byte button_number, bool active, bool selected); extern void KeyDown(); extern void KeyUp(); extern void ButtonPress(); extern void DoMenu(); -extern void ModeButtonPress(); extern void toggleiMSEQ(); extern void showBWSelector(); extern void updateiMS(); extern void updateEQ(); -extern void DataPrint(String string); extern void BuildAFScreen(); -extern void ShowFreq(int mode); diff --git a/lib/TFT_eSPI/TFT_eSPI.cpp b/lib/TFT_eSPI/TFT_eSPI.cpp index a46884d..aed9d26 100644 --- a/lib/TFT_eSPI/TFT_eSPI.cpp +++ b/lib/TFT_eSPI/TFT_eSPI.cpp @@ -44,7 +44,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) { SPI_BUSY_CHECK; uint32_t i = 0; - if (rem) { // len was not multiple of 32 + if(rem) { // len was not multiple of 32 for (i = 0; i < rem; i += 2) *spi_w++ = color32; *_spi_mosi_dlen = (rem << 4) - 1; // << 4 = * 16 *_spi_cmd = SPI_USR; @@ -343,11 +343,11 @@ void TFT_eSPI::init() { gpio_set_level((gpio_num_t)TFT_RST, 1); delay(3); gpio_set_level((gpio_num_t)TFT_RST, 0); - delay(12); + delay(10); gpio_set_level((gpio_num_t)TFT_RST, 1); } - delay(34); // Wait for reset to complete + delay(25); // Wait for reset to complete begin_tft_write(); diff --git a/lib/WiFiConnect/WC_AP_HTML.h b/lib/WiFiConnect/WC_AP_HTML.h index dd4769e..e6a6be8 100644 --- a/lib/WiFiConnect/WC_AP_HTML.h +++ b/lib/WiFiConnect/WC_AP_HTML.h @@ -1,16 +1,5 @@ -/*! - * @file WC_AP_HTML.h - * - * HTML snippets to build the Access Point portal and the Parameters Portal. - * - * Written by Stuart Blair - * - * GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file. - * - */ +#pragma once -#ifndef WC_AP_HTML -#define WC_AP_HTML ///< Define to stop re-inclusion /*! \def char AP_HTTP_HEAD[] PROGMEM Start of HTML output */ @@ -72,6 +61,4 @@ const char AP_HTTP_END[] PROGMEM = ""; /** HTML snippet for our custom parameters portal form */ const char AP_HTTP_PORTAL_PARAM_OPTIONS[] PROGMEM = "


"; /** HTML snippet for our custom parameters save */ -const char AP_HTTP_FORM_PARAM_START[] PROGMEM ="
"; - -#endif \ No newline at end of file +const char AP_HTTP_FORM_PARAM_START[] PROGMEM =""; \ No newline at end of file diff --git a/lib/WiFiConnect/WiFiConnect.cpp b/lib/WiFiConnect/WiFiConnect.cpp index fb6d366..44f2123 100644 --- a/lib/WiFiConnect/WiFiConnect.cpp +++ b/lib/WiFiConnect/WiFiConnect.cpp @@ -1,675 +1,170 @@ -/*! - @file WiFiConnect.cpp - - @mainpage WiFi Connection Manager with Captive Portal - - @section intro_sec Introduction - - This is the documentation for WiFiConnect for the Arduino platform https://github.com/smurf0969/WiFiConnect. - Further documentation can be found in the [Wiki](https://github.com/smurf0969/WiFiConnect/wiki) or in the project examples folder on GitHub. - - It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips. - - It contains a captive portal to allow easy connection and changing of WiFi netwoks - via a web based interface and allows for additional user parameters. - - It can also display messages via a OLED screen see WiFiConnectOLED class. - - ![alt text](https://github.com/smurf0969/WiFiConnect/raw/master/extras/screenshots.png "Screenshots") - - This is a heavily customised version from the origional WiFiManager - developed by https://github.com/tzapu . - - @section dependencies Dependencies - - This library depends on - ESP8266 Arduino Core or ESP32 Arduino Core depending on what chip you are using being present on your system. - Please make sure you have installed the latest version before using this library. - - @section arduino_libraries Arduino Libraries - - - ArduinoJson 6.9.1 [https://github.com/bblanchon/ArduinoJson.git](https://github.com/bblanchon/ArduinoJson.git) or [https://blog.benoitblanchon.fr](https://blog.benoitblanchon.fr) - - ESP8266 OLED SSD1306 ([Custom version](https://github.com/smurf0969/esp8266-oled-ssd1306/tree/Allow-overriding-default-font)) - - @section author Author - - Written by Stuart Blair. - - @section license License - - GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file. - -*/ #include "WiFiConnect.h" WiFiConnect::WiFiConnect() { - //_params = (WiFiConnectParam**)malloc(WiFiConnect_MAX_PARAMS * sizeof(WiFiConnectParam*)); _apName[0]='\0'; _apPassword[0]='\0'; } -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayConnecting(int attempt, int totalAttempts) { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayConnected() { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayAP() { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayParams() { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayManualReset() { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayTurnOFF(int ms) { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayLoop() { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief This function gets overridden by WiFiConnectOLED, - please view its documentation. -*/ -/**************************************************************************/ -void WiFiConnect::displayON() { - /*dummy*/ -} -/**************************************************************************/ -/*! - @brief Sets the timeout for when the Access Point is idle. - @param mins - The number of minutes to before exiting an idle access point. -*/ -/**************************************************************************/ -void WiFiConnect::setAPModeTimeoutMins(int mins) { - if (mins > 0) { - _apTimeoutMins = mins; - } -} -/**************************************************************************/ -/*! - @brief Sets the name for the Access Point, setting a default based on - the ESP chip id if needed. - @param apName - The new name for the access point. -*/ -/**************************************************************************/ -void WiFiConnect::setAPName(const char *apName) { - if(strlen(apName)>32){return;} - if (strlen(apName)==0||(apName == NULL)) { - String ssid = "ESP_" + String(ESP_getChipId()); - //_apName = ssid.c_str(); - strcpy(_apName,ssid.c_str()); - } else if (apName != NULL && strlen(apName)>0) { - // _apName = apName; - strcpy(_apName,apName); - } +void WiFiConnect::setAPModeTimeoutMins(int mins) { + if (mins > 0) _apTimeoutMins = mins; } -/**************************************************************************/ -/*! - @brief Gets the Access Point name or the default based on the - ESP chip id if not already set. - @return The name to be given to the access point. -*/ -/**************************************************************************/ + +void WiFiConnect::setAPName(const char *apName) { + if(strlen(apName)>32) return; + if(strlen(apName) == 0 || (apName == NULL)) { + String ssid = "ESP_" + String(ESP_getChipId()); + strcpy(_apName,ssid.c_str()); + } else if (apName != NULL && strlen(apName)>0) strcpy(_apName,apName); +} + const char* WiFiConnect::getAPName() { - if ((_apName == NULL ) || strlen(_apName)==0) { - setAPName(NULL); - } + if ((_apName == NULL ) || strlen(_apName)==0) setAPName(NULL); return _apName; } -/**************************************************************************/ -/*! - @brief Adds a custom parameter to be displayed in the accesspoint and - parameters portals. - Custom parameters can be used to save information that you do - not want to hard code i.e. IP address, Port number that can be - saved to the file system. - @param p - The custom parameter to add. -*/ -/**************************************************************************/ + void WiFiConnect::addParameter(WiFiConnectParam *p) { _params[_paramsCount] = p; _paramsCount++; - DEBUG_WC("Adding parameter"); - DEBUG_WC(p->getID()); } -/**************************************************************************/ -/*! - @brief Starts the custom Parameters Portal using default - access point name and password. - @return Returns wether WiFi is connected to a network -*/ -/**************************************************************************/ -boolean WiFiConnect::startParamsPortal() { - return startParamsPortal(AP_NONE, _apName, _apPassword); -} -/**************************************************************************/ -/*! - @brief Starts the custom Parameters Portal using default - access point name and password, but allows for specifying how - to continue. - @param apcontinue - What should the access point do if there is still no connection. - AP_NONE - continue running code, - AP_LOOP - stay in an infinate loop, - AP_RESET - Restart the ESP - AP_WAIT - Keep AP alive waiting for input - @return Returns wether WiFi is connected to a network if - AP_NONE is passed as a parameter -*/ -/**************************************************************************/ -boolean WiFiConnect::startParamsPortal(AP_Continue apcontinue) { - return startParamsPortal(apcontinue, _apName, _apPassword); -} -/**************************************************************************/ -/*! - @brief Starts the custom Parameters Portal. - @param apcontinue - What should the access point do if there is still no connection. - AP_NONE - continue running code, - AP_LOOP - stay in an infinate loop, - AP_RESET - Restart the ESP - AP_WAIT - Keep AP alive waiting for input - @param apName - The Name to use for the access point - @param apPassword - The optional Password to protect the access point - @return Returns wether WiFi is connected to a network if - AP_NONE is passed as a parameter -*/ -/**************************************************************************/ -boolean WiFiConnect::startParamsPortal(AP_Continue apcontinue, const char *apName, const char *apPassword) { - // Wrapper - return startConfigurationPortal(apcontinue, apName, apPassword, true); -} -/**************************************************************************/ -/*! - @brief Starts the Access Portal for setting SSID and Password for - connecting to a network and any custom user parameters. - Uses the default access point name and password. - @return Returns wether WiFi is connected to a network if - AP_NONE is passed as a parameter -*/ -/**************************************************************************/ boolean WiFiConnect::startConfigurationPortal() { - return startConfigurationPortal(AP_NONE, _apName, _apPassword); + return startConfigurationPortal(_apName, _apPassword); } -/**************************************************************************/ -/*! - @brief Starts the Access Portal for setting SSID and Password for - connecting to a network and any custom user parameters. - Uses the default access point name and password, but - allows for specifying how to continue if network not connected. - @param apcontinue - What should the access point do if there is still no connection. - AP_NONE - continue running code, - AP_LOOP - stay in an infinate loop, - AP_RESET - Restart the ESP - AP_WAIT - Keep AP alive waiting for input - @return Returns wether WiFi is connected to a network if - AP_NONE is passed as a parameter -*/ -/**************************************************************************/ -boolean WiFiConnect::startConfigurationPortal(AP_Continue apcontinue) { - return startConfigurationPortal(apcontinue, _apName, _apPassword); -} -/**************************************************************************/ -/*! - @brief Starts the Access Portal for setting SSID and Password for - connecting to a network and any custom user parameters. - @param apcontinue - What should the access point do if there is still no connection. - AP_NONE - continue running code, - AP_LOOP - stay in an infinate loop, - AP_RESET - Restart the ESP, handy for sensors if you network - goes down, do they keep trying to connect. - AP_WAIT - Keep AP alive waiting for input - @param apName - The Name to use for the access point - @param apPassword - The optional Password to protect the access point - @return Returns wether WiFi is connected to a network if - AP_NONE is passed as a parameter -*/ -/**************************************************************************/ -boolean WiFiConnect::startConfigurationPortal(AP_Continue apcontinue, const char *apName, const char *apPassword, bool paramsMode) { - if (paramsMode) { - DEBUG_WC(F("WiFi AP STA - Parameters Portal")); - } else { - DEBUG_WC(F("WiFi AP STA - Configuration Portal")); - } +boolean WiFiConnect::startConfigurationPortal(const char *apName, const char *apPassword, bool paramsMode) { _lastAPPage = millis(); - delay(50); + delay(50); // Huh? if (WiFi.status() != WL_CONNECTED) { - if (paramsMode) { - // Can't show the parameters portal if not connected to a WiFi network. - startConfigurationPortal(AP_WAIT, apName, apPassword, false); - } else { - DEBUG_WC("startConfigurationPortal(): WiFi.mode(WIFI_AP)"); - WiFi.mode(WIFI_AP); - } - } else { - WiFi.mode(WIFI_AP_STA); // start an access point on the same channel we're already connected to. - } + if (paramsMode) startConfigurationPortal(apName, apPassword, false); + else WiFi.mode(WIFI_AP); + } else WiFi.mode(WIFI_AP_STA); // start an access point on the same channel we're already connected to. dnsServer.reset(new DNSServer()); -#ifdef ESP8266 - server.reset(new ESP8266WebServer(80)); -#else server.reset(new WebServer(80)); -#endif setAPName(apName); - DEBUG_WC(_apName); if (strlen(apPassword)>0){ - if (strlen(apPassword) < 8 || strlen(apPassword) > 63) { - // fail passphrase to short or long! - DEBUG_WC(F("Invalid AccessPoint password. Ignoring")); - apPassword = NULL; - } - //_apPassword = apPassword; + if (strlen(apPassword) < 8 || strlen(apPassword) > 63) apPassword = NULL; strcpy(_apPassword,apPassword); - DEBUG_WC(_apPassword); } - //optional soft ip config - if (_ap_static_ip) { - DEBUG_WC(F("Custom AP IP/GW/Subnet")); - WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); - } + if (_ap_static_ip) WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); - //if (_apPassword != NULL && _apPassword!="") { - if(strlen(apPassword)>0){ - WiFi.softAP(_apName, _apPassword);//password option - } else { - WiFi.softAP(_apName); - DEBUG_WC("startConfigurationPortal(): WiFi.softAP(_apName)"); - } + if(strlen(apPassword) > 0) WiFi.softAP(_apName, _apPassword);//password option + else WiFi.softAP(_apName); + + delay(450); - delay(500); // Without delay I've seen the IP address blank - DEBUG_WC(F("AP IP address: ")); - DEBUG_WC(WiFi.softAPIP()); - - // Show on OLED depending on the mode - if (!paramsMode) { displayAP(); } else { displayParams(); } - - /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); - dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); + dnsServer->start(53, "*", WiFi.softAPIP()); - if (paramsMode) - { - + if (paramsMode) { server->on("/", std::bind(&WiFiConnect::handleParamRoot, this)); server->on("/param", std::bind(&WiFiConnect::handleParams, this)); server->on("/params", std::bind(&WiFiConnect::handleParams, this)); server->on("/wifisave", std::bind(&WiFiConnect::handleWifiSave, this)); server->on("/i", std::bind(&WiFiConnect::handleInfo, this)); - //server->on("/r", std::bind(&WiFiConnect::handleReset, this)); // doesn't work - causes boot loop - //server->on("/generate_204", std::bind(&WiFiConnect::handle204, this)); //Android/Chrome OS captive portal check. server->on("/fwlink", std::bind(&WiFiConnect::handleParamRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server->on("/hotspot_detect.html", std::bind(&WiFiConnect::handleParamRoot, this)); - } else { // Config portal mode - - /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */ server->on("/", std::bind(&WiFiConnect::handleRoot, this)); server->on("/wifi", std::bind(&WiFiConnect::handleWifi, this, true)); // Auto Scan of APs server->on("/0wifi", std::bind(&WiFiConnect::handleWifi, this, false)); // Manual entry form only server->on("/wifisave", std::bind(&WiFiConnect::handleWifiSave, this)); server->on("/i", std::bind(&WiFiConnect::handleInfo, this)); // Not of interest - commented out in static HTML server->on("/r", std::bind(&WiFiConnect::handleReset, this)); - //server->on("/generate_204", std::bind(&WiFiConnect::handle204, this)); //Android/Chrome OS captive portal check. server->on("/fwlink", std::bind(&WiFiConnect::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server->on("/hotspot_detect.html", std::bind(&WiFiConnect::handleRoot, this)); - - } // config portal + } // config portal - server->onNotFound (std::bind(&WiFiConnect::handleNotFound, this)); - server->begin(); // Web server start - DEBUG_WC(F("HTTP server started")); - - //notify we entered AP mode - if ( _apcallback != NULL) { - _apcallback(this); - } - - if (apcontinue == AP_WAIT) - DEBUG_WC(F("AP to stay alive indefinitely waiting for configuration.")); - + server->onNotFound(std::bind(&WiFiConnect::handleNotFound, this)); + server->begin(); // Web server start _lastAPPage = millis(); - _readyToConnect = false; + _readyToConnect = false; while (true) { - if (apcontinue != AP_WAIT) { - if (millis() - (unsigned long int)_lastAPPage >= ( (unsigned int)_apTimeoutMins * 60 * 1000)) { - break; - } - } - dnsServer->processNextRequest(); server->handleClient(); if (_readyToConnect) { _readyToConnect = false; - DEBUG_WC(F("startConfigurationPortal(): Calling: autoConnect(_ssid.c_str(), _password.c_str(), WIFI_AP_STA)")); - if (autoConnect(_ssid.c_str(), _password.c_str(), WIFI_AP_STA)) { - - DEBUG_WC(F("Connection was a success, so changing to WIFI_STA mode only.")); + WiFi.mode(WIFI_STA); delay(500); - //WiFi.reconnect(); - //delay(500); - if (_savecallback != NULL) { - _savecallback(); - } break; // we connected! } - else - { - DEBUG_WC(F("Connection was a failure. We keep waiting.")); - } } // ready to connect - + yield(); } - + //teardown?? - DEBUG_WC(F("Exiting AP (or AP Params) Mode")); server->close(); server.reset(); dnsServer.reset(); boolean con = (WiFi.status() == WL_CONNECTED); - if (!con) { - switch (apcontinue) { - case AP_WAIT: - break; - case AP_NONE: - DEBUG_WC(F("No AP continue action")); - break; - case AP_LOOP: - DEBUG_WC(F("AP to turn off and stay in loop lockup not being accessible.")); - displayManualReset(); - displayTurnOFF(5 * 60 * 100); //5mins - WiFi.mode(WIFI_OFF); - while (true) { - displayLoop(); - delay(1000); - yield(); - } - - break; - case AP_RESTART: - case AP_RESET: - displayManualReset(); - DEBUG_WC(F("AP restart chip")); - delay(1000); -#if defined(ESP8266) - ESP.reset(); -#else - ESP.restart(); -#endif - delay(2000); - } - WiFi.mode(WIFI_STA); - } + if (!con) WiFi.mode(WIFI_STA); return con; } -/**************************************************************************/ -/*! - @brief Tries to connect to the last connected WiFi network. - @return Returns wether WiFi is connected - @section example_startConfigurationPortal Example - - The return value can be used to automatically start the access point - so you may change networks if required. - - @code - if(!wificonnect.autoConnect()){ - //Start the access point - wificonnect.startConfigurationPortal(); - } - @endcode -*/ -/**************************************************************************/ boolean WiFiConnect::autoConnect() { return autoConnect(NULL, NULL, WIFI_STA); } -/**************************************************************************/ -/*! - @brief Tries to connect to the specified WiFi network. - @param ssidName - The SSID of the netqork you want to connect to. - @param ssidPassword - The password for a secure network. - @param WiFiMode - The WiFi mode - @return Returns wether WiFi is connected -*/ -/**************************************************************************/ + boolean WiFiConnect::autoConnect(char const *ssidName, char const *ssidPassword, WiFiMode_t acWiFiMode) { -/* - #ifdef ESP32 - WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work (from WiFiManager) - #endif -*/ - - DEBUG_WC(F("Auto Connect")); WiFi.mode(acWiFiMode); - DEBUG_WC("autoConnect():WiFi.mode(acWiFiMode)"); - if (WiFi.status() == WL_CONNECTED) { - DEBUG_WC(F("Already Connected")); - DEBUG_WC(WiFi.localIP()); - return true; - } - if (_sta_static_ip) { - DEBUG_WC(F("Custom STA IP/GW/Subnet")); - WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); - DEBUG_WC(WiFi.localIP()); - } - - //fix for auto connect racing issue - /* - if (WiFi.status() == WL_CONNECTED && (WiFi.SSID() == String(ssidName))) { - DEBUG_WC(F("Already connected. Bailing out.")); - DEBUG_WC(WiFi.localIP()); - return true; - //return WL_CONNECTED; - } -*/ - + if (WiFi.status() == WL_CONNECTED) return true; + if (_sta_static_ip) WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); int c = 0; while (c < _retryAttempts) { - displayConnecting(c + 1, _retryAttempts); long ms = millis(); if (ssidName == NULL || strlen(ssidName)==0) { - - #ifdef ESP8266 - if (WiFi.SSID() == "") - { - DEBUG_WC(F("No ESP8266 WiFi SSID configuration stored. Bailing.")); - return false; - } - DEBUG_WC(F("Stored SSID:")); DEBUG_WC(WiFi.SSID()); - #endif - - #ifdef ESP32 - // WiFi.SSID() Always returns null on ESP32.... Arduino framework bug? - // So use lower-level IDF function to pull persistent configuration. wifi_config_t conf; esp_wifi_get_config(WIFI_IF_STA, &conf); String stored_ssid = String(reinterpret_cast(conf.sta.ssid)); - if (stored_ssid == "") - { - DEBUG_WC(F("No ESP32 WiFi SSID configuration stored. Bailing.")); - return false; - } - - DEBUG_WC(F("Stored SSID:")); DEBUG_WC(stored_ssid); - #endif - - + if (stored_ssid == "") return false; WiFi.begin(); // persistence is on by default, so if this WiFi connection should happen automatically - DEBUG_WC("autoConnect(): WiFi.begin()"); - -/* - #ifdef ESP32 - //https://forum.arduino.cc/index.php?topic=652513.0 - int wifi_retry = 0; // COUNTER SOLVES ESP32-BUG WITH CERTAIN ROUTERS: CONNECTION ONLY ESTABLISHED EVERY SECOND TIME - - while (WiFi.waitForConnectResult() != WL_CONNECTED && wifi_retry < 3) { - DEBUG_WC("WLAN Not yet connected on ESP32...retrying"); - WiFi.begin(); - delay(250); - wifi_retry++; - } - - #endif -*/ - - } else { - DEBUG_WC(F("Connecting with SSID & Password")); - DEBUG_WC(ssidName); - DEBUG_WC(ssidPassword); - WiFi.begin(ssidName, ssidPassword); - DEBUG_WC("autoConnect(): WiFi.begin(ssidName, ssidPassword)"); - } - + } else WiFi.begin(ssidName, ssidPassword); while (millis() - (unsigned long int)ms < ( (unsigned int)_connectionTimeoutSecs * 1000)) { int ws = WiFi.status(); if (ws == WL_CONNECTED) { - DEBUG_WC(F("WIFI_CONNECTED")); delay(500);//wait for ip to refresh - DEBUG_WC(WiFi.localIP()); - displayConnected(); return true; } else if (ws == WL_CONNECT_FAILED) { - DEBUG_WC(F("WIFI_CONNECT_FAILED")); delay(500); - //return false; } else { delay(200); yield(); } - } - DEBUG_WC(statusToString(WiFi.status())); - c++; + } c++; } // attemps - DEBUG_WC(statusToString(WiFi.status())); return false; } -/**************************************************************************/ -/*! - @brief Sets how many times we should try to connect to the WiFi network. - @param attempts - How may attampts. -*/ -/**************************************************************************/ + void WiFiConnect::setRetryAttempts(int attempts) { if (attempts >= 1) { _retryAttempts = attempts; } } -/**************************************************************************/ -/*! - @brief Sets how long to wait for the connection before failing. - @param timeout - How may seconds to wait for the connection to be made. -*/ -/**************************************************************************/ + void WiFiConnect::setConnectionTimeoutSecs(int timeout) { - if (timeout >= 1) { - _connectionTimeoutSecs = timeout; - } + if (timeout >= 1) _connectionTimeoutSecs = timeout; } -/**************************************************************************/ -/*! - @brief A helper to clear the settings for the last connected network. - Remember to comment out or remove and re-upload your code - otherwise chip will constantly restart. -*/ -/**************************************************************************/ + void WiFiConnect::resetSettings() { - DEBUG_WC(F("Clearing Settings for:")); - DEBUG_WC(WiFi.SSID()); -#if defined(ESP8266) WiFi.disconnect(true); - delay(1000); - ESP.reset(); -#else - WiFi.disconnect(true);//doesnt seem to work - esp_wifi_restore();//doesnt seem to work - WiFi.begin("0", "0"); //HACK + esp_wifi_restore(); + WiFi.begin("0", "0"); delay(1000); ESP.restart(); -#endif delay(2000); } -/**************************************************************************/ -/*! - @brief A helper function to return the string version of a - wifi network state. - @param state - The state that we want the string representation of. - @return WiFi state as a string. -*/ -/**************************************************************************/ + const char* WiFiConnect::statusToString(int state) { switch (state) { case WL_CONNECTED: @@ -692,20 +187,7 @@ const char* WiFiConnect::statusToString(int state) { return "UNKNOWN CODE"; } } -/**************************************************************************/ -/*! - @brief Outputs debug messages - @param text - The text to be outputted -*/ -/**************************************************************************/ -template -void WiFiConnect::DEBUG_WC(Generic text) { - if (_debug) { - Serial.print("*WC: "); - Serial.println(text); - } -} + /**************************************************************************/ /*! @brief Handles the web request for root in the Parameters Portal and @@ -717,7 +199,6 @@ void WiFiConnect::handleParamRoot() { return; } _lastAPPage = millis(); - DEBUG_WC("Sending Root"); String page = FPSTR(AP_HTTP_HEAD); page.replace("{v}", "Options"); page += FPSTR(AP_HTTP_SCRIPT); @@ -742,7 +223,6 @@ void WiFiConnect::handleParamRoot() { /**************************************************************************/ void WiFiConnect::handleParams() { _lastAPPage = millis(); - DEBUG_WC(F("Sending Params")); String page = FPSTR(AP_HTTP_HEAD); page.replace("{v}", "Config Params"); @@ -794,7 +274,6 @@ void WiFiConnect::handleRoot() { return; } _lastAPPage = millis(); - DEBUG_WC("Sending Root"); String page = FPSTR(AP_HTTP_HEAD); page.replace("{v}", "Options"); page += FPSTR(AP_HTTP_SCRIPT); @@ -825,7 +304,6 @@ void WiFiConnect::handleRoot() { void WiFiConnect::handleWifi(boolean scan) { _lastAPPage = millis(); - DEBUG_WC(F("Sending WiFi")); String page = FPSTR(AP_HTTP_HEAD); page.replace("{v}", "Select WiFi"); @@ -835,9 +313,7 @@ void WiFiConnect::handleWifi(boolean scan) { if (scan) { int n = WiFi.scanNetworks(); - DEBUG_WC(F("Scan done")); if (n == 0) { - DEBUG_WC(F("No networks found")); page += F("No networks found. Refresh to scan again."); } else { @@ -858,22 +334,13 @@ void WiFiConnect::handleWifi(boolean scan) { } } - /*std::sort(indices, indices + n, [](const int & a, const int & b) -> bool - { - return WiFi.RSSI(a) > WiFi.RSSI(b); - });*/ - - // remove duplicates ( must be RSSI sorted ) - if (_removeDuplicateAPs) { - String cssid; - for (int i = 0; i < n; i++) { - if (indices[i] == -1) continue; - cssid = WiFi.SSID(indices[i]); - for (int j = i + 1; j < n; j++) { - if (cssid == WiFi.SSID(indices[j])) { - DEBUG_WC("DUP AP: " + WiFi.SSID(indices[j])); - indices[j] = -1; // set dup aps to index -1 - } + String cssid; + for (int i = 0; i < n; i++) { + if (indices[i] == -1) continue; + cssid = WiFi.SSID(indices[i]); + for (int j = i + 1; j < n; j++) { + if (cssid == WiFi.SSID(indices[j])) { + indices[j] = -1; // set dup aps to index -1 } } } @@ -881,8 +348,6 @@ void WiFiConnect::handleWifi(boolean scan) { //display networks in page for (int i = 0; i < n; i++) { if (indices[i] == -1) continue; // skip dups - DEBUG_WC(WiFi.SSID(indices[i])); - DEBUG_WC(WiFi.RSSI(indices[i])); int quality = getRSSIasQuality(WiFi.RSSI(indices[i])); if (_minimumQuality == -1 || _minimumQuality < quality) { @@ -903,10 +368,7 @@ void WiFiConnect::handleWifi(boolean scan) { //DEBUG_WM(item); page += item; delay(0); - } else { - DEBUG_WC(F("Skipping due to quality")); } - } page += "
"; } @@ -981,23 +443,10 @@ void WiFiConnect::handleWifi(boolean scan) { } void WiFiConnect::handleWifiSave() { _lastAPPage = millis(); - DEBUG_WC(F("Sending WiFi Save")); - //SAVE/connect here - if (_debug) { - Serial.println(F("*WC Form Args")); - for (int x = 0; x < server->args(); x++) { - Serial.print(F("*WC ")); - Serial.print(server->argName(x)); - Serial.print(F("=")); - Serial.println(server->arg(x)); - } - } _ssid = server->arg("s").c_str(); _ssid.trim(); - DEBUG_WC(_ssid); _password = server->arg("p").c_str(); _password.trim(); - DEBUG_WC(_password); //parameters for (int i = 0; i < _paramsCount; i++) { if (_params[i] == NULL) { @@ -1007,27 +456,18 @@ void WiFiConnect::handleWifiSave() { String value = server->arg(_params[i]->getID()).c_str(); //store it in array value.toCharArray(_params[i]->_value, _params[i]->_length); - DEBUG_WC(F("Parameter")); - DEBUG_WC(_params[i]->getID()); - DEBUG_WC(value); } if (server->arg("ip") != "") { - DEBUG_WC(F("static ip")); - DEBUG_WC(server->arg("ip")); //_sta_static_ip.fromString(server->arg("ip")); String ip = server->arg("ip"); optionalIPFromString(&_sta_static_ip, ip.c_str()); } if (server->arg("gw") != "") { - DEBUG_WC(F("static gateway")); - DEBUG_WC(server->arg("gw")); String gw = server->arg("gw"); optionalIPFromString(&_sta_static_gw, gw.c_str()); } if (server->arg("sn") != "") { - DEBUG_WC(F("static netmask")); - DEBUG_WC(server->arg("sn")); String sn = server->arg("sn"); optionalIPFromString(&_sta_static_sn, sn.c_str()); } @@ -1052,7 +492,7 @@ void WiFiConnect::handleWifiSave() { */ /**************************************************************************/ void WiFiConnect::handleInfo() { - _lastAPPage = millis(); DEBUG_WC(F("Sending Info")); + _lastAPPage = millis(); String page = FPSTR(AP_HTTP_HEAD); page.replace("{v}", "Info"); @@ -1096,8 +536,6 @@ void WiFiConnect::handleInfo() { server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); - - DEBUG_WC(F("Sent info page")); } /**************************************************************************/ /*! @@ -1107,7 +545,6 @@ void WiFiConnect::handleInfo() { /**************************************************************************/ void WiFiConnect::handleReset() { _lastAPPage = millis(); - DEBUG_WC(F("Sending Reset")); String page = FPSTR(AP_HTTP_HEAD); page.replace("{v}", "Info"); @@ -1120,15 +557,9 @@ void WiFiConnect::handleReset() { server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); - DEBUG_WC(F("Sent reset page")); delay(5000); -#if defined(ESP8266) - ESP.reset(); // causes boot loop -#else ESP.restart(); -#endif delay(2000); - } /**************************************************************************/ /*! @@ -1137,7 +568,6 @@ void WiFiConnect::handleReset() { /**************************************************************************/ void WiFiConnect::handle204() { _lastAPPage = millis(); - DEBUG_WC(F("Sending 204")); handleRoot(); } /**************************************************************************/ @@ -1147,11 +577,9 @@ void WiFiConnect::handle204() { /**************************************************************************/ void WiFiConnect::handleNotFound() { if (captivePortal()) { // If captive portal redirect instead of displaying the error page. - DEBUG_WC(F("Webserver called handleNotFound();")); return; } _lastAPPage = millis(); - DEBUG_WC(F("Sending Not Found")); String message = "File Not Found\n\n"; message += "URI: "; message += server->uri(); @@ -1181,11 +609,8 @@ void WiFiConnect::handleNotFound() { */ /**************************************************************************/ boolean WiFiConnect::captivePortal() { - DEBUG_WC(server->hostHeader()); - if (!isIp(server->hostHeader()) ) { _lastAPPage = millis(); - DEBUG_WC(F("Request redirected to captive portal")); String msg = "redirect\n"; server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true); server->sendHeader("Content-Length", String(msg.length())); @@ -1197,42 +622,6 @@ boolean WiFiConnect::captivePortal() { return false; } -/**************************************************************************/ -/*! - @brief Sets the function to be called when we enter Access Point - for configuration. - Gets passed a the WiFiConnect for additional usage within function. - @param func - The function to be called. - -*/ -/**************************************************************************/ -void WiFiConnect::setAPCallback( void (*func)(WiFiConnect* myWiFiConnect) ) { - _apcallback = func; -} -/**************************************************************************/ -/*! - @brief Sets the function to be called when we need to save the - custom parameters/configuration. - @param func - The function to be called. - This function should be short running and ideally just set. - a flag for processing else where. -*/ -/**************************************************************************/ -void WiFiConnect::setSaveConfigCallback( void (*func)() ) { - _savecallback = func; -} -/**************************************************************************/ -/*! - @brief Function to convert RSSI into a usable range 0-100 so we can - use it to exclude poor networks. - @param RSSI - The quality/signal strength of the WiFi network. - @return Value in the range of 0-100 to network indicate quality. - -*/ -/**************************************************************************/ int WiFiConnect::getRSSIasQuality(int RSSI) { int quality = 0; @@ -1245,15 +634,7 @@ int WiFiConnect::getRSSIasQuality(int RSSI) { } return quality; } -/**************************************************************************/ -/*! - @brief Function to check if a given string is an IP Address. - @param str - The string to process. - @return True if inputted string is an IP Address. -*/ -/**************************************************************************/ boolean WiFiConnect::isIp(String str) { for (unsigned int i = 0; i < str.length(); i++) { int c = str.charAt(i); @@ -1263,15 +644,7 @@ boolean WiFiConnect::isIp(String str) { } return true; } -/**************************************************************************/ -/*! - @brief Function to return a IPAddress as a string representation. - @param ip - The IPAddress to process. - @return String version of the IPAddress -*/ -/**************************************************************************/ String WiFiConnect::toStringIp(IPAddress ip) { String res = ""; for (int i = 0; i < 3; i++) { @@ -1280,49 +653,14 @@ String WiFiConnect::toStringIp(IPAddress ip) { res += String(((ip >> 8 * 3)) & 0xFF); return res; } -/**************************************************************************/ -/*! - @brief Used to turn on or off messages to the serial port/monitor. - @param isDebug - Set to true to enable messages. -*/ -/**************************************************************************/ -void WiFiConnect::setDebug(boolean isDebug) { - _debug = isDebug; -} -/**************************************************************************/ -/*! - @brief Used to set a static ip/gateway and subnet mask for the access point. - IP and DNS Gateway are normally the same for a captive portal. - @param ip - The IP address that you want to access the portal through. - @param gw - The gateway address for the DNS server, usually the same as IP for - captive portal. - @param sn - The subnet mask for the access point, usually 255.255.255.0 -*/ -/**************************************************************************/ -void WiFiConnect::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { +void WiFiConnect::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { _ap_static_ip = ip; _ap_static_gw = gw; _ap_static_sn = sn; } -/**************************************************************************/ -/*! - @brief Used to set a static ip/gateway and subnet mask for the local - network. - @param ip - The IP address that you want to use on the network. - @param gw - The gateway address for the DNS server or network router. - @param sn - The subnet mask for the access point, usually 255.255.255.0 - for local networks. -*/ -/**************************************************************************/ -void WiFiConnect::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { + +void WiFiConnect::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { _sta_static_ip = ip; _sta_static_gw = gw; _sta_static_sn = sn; diff --git a/lib/WiFiConnect/WiFiConnect.h b/lib/WiFiConnect/WiFiConnect.h index d3b340c..c26de57 100644 --- a/lib/WiFiConnect/WiFiConnect.h +++ b/lib/WiFiConnect/WiFiConnect.h @@ -1,85 +1,28 @@ -/*! - @file WiFiConnect.h - - This is the documentation for WiFiConnect for the Arduino platform. - It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips. - It contains a captive portal to allow easy connection and changing of WiFi netwoks - via a web based interface and allows for additional user parameters. - - You can view the project at https://github.com/smurf0969/WiFiConnect. - Further information is also available in the project Wiki. - - This is a heavily customised version from the origional WiFiManager - developed by https://github.com/tzapu . - - This library depends on - ESP8266 Arduino Core and ESP32 Arduino Core being present on your system. - Please make sure you have installed the latest version before using this library. - - Written by Stuart Blair. - - GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file. - -*/ -#ifndef WiFiConnect_h -#define WiFiConnect_h +#pragma once #include -#if defined(ESP8266) -#include -#include -#else #include #include using fs::FS; #include -#endif #include #include -#if defined(ESP8266) -extern "C" { -#include "user_interface.h" -} -#define ESP_getChipId() (ESP.getChipId()) ///< Gets an ID from the chip -#else #include #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())///< Gets an ID from the chip -#endif #include "WC_AP_HTML.h" #include "WiFiConnectParam.h" -/** Options for how a access point should continue if no WiFi connected */ -enum AP_Continue { - AP_NONE, ///< No action, continues to run code - AP_LOOP, ///< Stalls execution with an infinate loop - AP_RESTART, ///< Restarts the chip, allowing it to try to setup again. Handy for sensors when wifi is lost. - AP_RESET, ///< Same as AP_RESTART - AP_WAIT // Keep the AP and webserver running, sit quietly and be patient. -}; -/**************************************************************************/ -/*! - @brief Class that helps to connect to WiFi networks, that also has - captive portal web interface for configuration. - This is the base class for WiFiConntectOLED which displays - information on a OLED display. -*/ -/**************************************************************************/ + class WiFiConnect { public: - /// Create WiFiConnect class WiFiConnect(); boolean startConfigurationPortal(); - boolean startConfigurationPortal(AP_Continue apcontinue); - boolean startConfigurationPortal(AP_Continue apcontinue, const char* apName, const char* apPassword = NULL, bool paramsMode = false); - - boolean startParamsPortal(); - boolean startParamsPortal(AP_Continue apcontinue); - boolean startParamsPortal(AP_Continue apcontinue, const char* apName, const char* apPassword = NULL); + boolean startConfigurationPortal(const char* apName, const char* apPassword = NULL, bool paramsMode = false); void addParameter(WiFiConnectParam *p); - void setAPName(const char* apName); + void setAPName(const char* apName); const char* getAPName(); void resetSettings(); @@ -87,83 +30,46 @@ class WiFiConnect { boolean autoConnect(); boolean autoConnect(const char* ssidName, const char* ssidPassword = NULL, WiFiMode_t acWiFiMode = WIFI_STA); - - //sets a custom ip /gateway /subnet configuration - void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn); - //sets config for a static IP - void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn); - - //called when AP mode and config portal is started - void setAPCallback( void (*func)(WiFiConnect*) ); - //called when settings have been changed and connection was successful - void setSaveConfigCallback( void (*func)() ); - - void setDebug(boolean isDebug); + void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn); + void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn); void setRetryAttempts(int attempts); void setConnectionTimeoutSecs(int timeout); void setAPModeTimeoutMins(int mins); - boolean captivePortal(); + boolean captivePortal(); //helpers const char* statusToString(int state); - int getRSSIasQuality(int RSSI); - boolean isIp(String str); - String toStringIp(IPAddress ip); - virtual void displayTurnOFF(int ms = 5000); ///< Virtual method overriden in WiFiConnectOLED - virtual void displayLoop(); ///< Virtual method overriden in WiFiConnectOLED - virtual void displayON(); ///< Virtual method overriden in WiFiConnectOLED - protected: - boolean _debug = false; ///< Flag to determine wheter to output mesages or not - template - void DEBUG_WC(Generic text); - virtual void displayConnecting(int attempt, int totalAttempts); ///< Virtual method overriden in WiFiConnectOLED - virtual void displayConnected(); ///< Virtual method overriden in WiFiConnectOLED - virtual void displayAP(); ///< Virtual method overriden in WiFiConnectOLED - virtual void displayParams(); ///< Virtual method overriden in WiFiConnectOLED - virtual void displayManualReset(); ///< Virtual method overriden in WiFiConnectOLED - + int getRSSIasQuality(int RSSI); + boolean isIp(String str); + String toStringIp(IPAddress ip); private: - - int _retryAttempts = 3; ///< Number of attempts when trying to connect to WiFi network int _connectionTimeoutSecs = 10; ///< How log to wait for the connection to succeed or fail int _apTimeoutMins = 3; ///< The amount of minutes of inactivity before the access point exits it routine - // DNS server - const byte DNS_PORT = 53; ///< Standard DNS Port number - - long _lastAPPage = 0; ///< The last time a page was accessed in the portal. Used for the inactivity timeout. - boolean _removeDuplicateAPs = true; ///< Flag to remove duplicate networks from scan results. - int _minimumQuality = 8; ///< The minimum netqork quality to be included in scan results. - int _paramsCount = 0; ///< The amount of custom parameters added via addParameter - boolean _readyToConnect = false; ///< Flag used in access point to determine if it should try to connect to the network. - String _ssid = " "; ///< Tempory holder for the network ssid - String _password = " "; ///< Tempory holder for the network password + + long _lastAPPage = 0; + int _minimumQuality = 8; + int _paramsCount = 0; + boolean _readyToConnect = false; + String _ssid = " "; + String _password = " "; WiFiConnectParam* _params[WiFiConnect_MAX_PARAMS]; ///< Array to hold custom parameters - std::unique_ptr dnsServer; ///< DNS Server for captive portal to redirect to Access Point -#ifdef ESP8266 - std::unique_ptr server; ///< Web server for serving access point pages -#else - std::unique_ptr server; ///< Web server for serving access point pages -#endif + std::unique_ptr dnsServer; + std::unique_ptr server; - char _apName[33] ; ///< Holder for the access point name - char _apPassword[65] ; ///< Holder for the access point password + char _apName[33]; + char _apPassword[65]; - IPAddress _ap_static_ip; ///< Variable for holding Static IP Address for the access point - IPAddress _ap_static_gw; ///< Variable for holding Static Gateway IP Address for the access point - IPAddress _ap_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the access point - IPAddress _sta_static_ip; ///< Variable for holding Static IP Address for the network connection - IPAddress _sta_static_gw; ///< Variable for holding Static Gateway IP Address for the network connection - IPAddress _sta_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the network connection - - void (*_apcallback)(WiFiConnect*) = NULL; - void (*_savecallback)() = NULL; - - + IPAddress _ap_static_ip; ///< Variable for holding Static IP Address for the access point + IPAddress _ap_static_gw; ///< Variable for holding Static Gateway IP Address for the access point + IPAddress _ap_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the access point + IPAddress _sta_static_ip; ///< Variable for holding Static IP Address for the network connection + IPAddress _sta_static_gw; ///< Variable for holding Static Gateway IP Address for the network connection + IPAddress _sta_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the network connection void handleRoot(); void handleParamRoot(); @@ -176,14 +82,6 @@ class WiFiConnect { void handleNotFound(); template - auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) { - return obj->fromString(s); - } - auto optionalIPFromString(...) -> bool { - DEBUG_WC("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work."); - return false; - } - + auto optionalIPFromString(T *obj, const char *s) -> decltype(obj->fromString(s)) { return obj->fromString(s); } + bool optionalIPFromString(...) {return false;} }; - -#endif diff --git a/lib/WiFiConnect/WiFiConnectParam.cpp b/lib/WiFiConnect/WiFiConnectParam.cpp index dc3f553..268e84c 100644 --- a/lib/WiFiConnect/WiFiConnectParam.cpp +++ b/lib/WiFiConnect/WiFiConnectParam.cpp @@ -1,41 +1,5 @@ -/*! - @file WiFiConnectParam.cpp - - WiFi Connection Manager with Captive Portal - - Introduction - - This is the documentation for WiFiConnect for the Arduino platform. - It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips. - It contains a captive portal to allow easy connection and changing of WiFi netwoks - via a web based interface and allows for additional user parameters. - It can also display messages via a OLED screen see WiFiConnectOLED class. - - This is a heavily customised version from the original WiFiManager - developed by https://github.com/tzapu . - - Dependencies - - This library depends on - ESP8266 Arduino Core and ESP32 Arduino Core being present on your system. - Please make sure you have installed the latest version before using this library. - - - Written by Stuart Blair. - - License - - GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file. - -*/ #include "WiFiConnectParam.h" -/**************************************************************************/ -/*! - @brief Class object initialiser - @param custom - Custom HTML to be displayed in the access point for this item. -*/ -/**************************************************************************/ + WiFiConnectParam::WiFiConnectParam(const char *custom) { _id = NULL; _placeholder = NULL; @@ -44,55 +8,14 @@ WiFiConnectParam::WiFiConnectParam(const char *custom) { _customHTML = custom; } -/**************************************************************************/ -/*! - @brief Class object initialiser - @param id - The unique ID for the html input box markup for this item - @param placeholder - Text to be displayed as the input box placeholder for this item - @param defaultValue - Default text to be displayed in the input box for this item - @param length - The maximum input text length for this item -*/ -/**************************************************************************/ + WiFiConnectParam::WiFiConnectParam(const char *id, const char *placeholder, const char *defaultValue, int length) { init(id, placeholder, defaultValue, length, ""); } -/**************************************************************************/ -/*! - @brief Class object initialiser - @param id - The unique ID for the html input box markup for this item - @param placeholder - Text to be displayed as the input box placeholder for this item - @param defaultValue - Default text to be displayed in the input box for this item - @param length - The maximum input text length for this item - @param custom - Custom HTML to be displayed in the access point for this item. -*/ -/**************************************************************************/ WiFiConnectParam::WiFiConnectParam(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { init(id, placeholder, defaultValue, length, custom); } -/**************************************************************************/ -/*! - @brief Initialiser method - @param id - The unique ID for the html input box markup for this item - @param placeholder - Text to be displayed as the input box placeholder for this item - @param defaultValue - Default text to be displayed in the input box for this item - @param length - The maximum input text length for this item - @param custom - Custom HTML to be displayed in the access point for this item. -*/ -/**************************************************************************/ + void WiFiConnectParam::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { _id = id; _placeholder = placeholder; @@ -101,66 +24,32 @@ void WiFiConnectParam::init(const char *id, const char *placeholder, const char _customHTML = custom; } -/**************************************************************************/ -/*! - @brief Method to change the current value of the item - @param newValue - The new string value for the item -*/ -/**************************************************************************/ + void WiFiConnectParam::setValue(const char *newValue){ - if(_length>0){ - _value = new char[_length + 1]; - for (int i = 0; i < _length; i++) { - _value[i] = 0; - } - if (newValue != NULL) { - strncpy(_value, newValue, _length); - } + if(_length > 0) { + // you know what was here in upstream + _value = new char[_length + 1]; + for (int i = 0; i < _length; i++) _value[i] = 0; + if (newValue != NULL) strncpy(_value, newValue, _length); } } -/**************************************************************************/ -/*! - @brief Function to get the current value of the item - @return The current value -*/ -/**************************************************************************/ + const char* WiFiConnectParam::getValue() { return _value; } -/**************************************************************************/ -/*! - @brief Function to get the current id of the item - @return The current id -*/ -/**************************************************************************/ + const char* WiFiConnectParam::getID() { return _id; } -/**************************************************************************/ -/*! - @brief Function to get the current placeholder text of the item - @return The current placeholder text -*/ -/**************************************************************************/ + const char* WiFiConnectParam::getPlaceholder() { return _placeholder; } -/**************************************************************************/ -/*! - @brief Function to get the maximum length allowed for the value of the item - @return The current maximum value length -*/ -/**************************************************************************/ + int WiFiConnectParam::getValueLength() { return _length; } -/**************************************************************************/ -/*! - @brief Function to get the current custom html markup of the item - @return The current custom html markup -*/ -/**************************************************************************/ + const char* WiFiConnectParam::getCustomHTML() { return _customHTML; } diff --git a/lib/WiFiConnect/WiFiConnectParam.h b/lib/WiFiConnect/WiFiConnectParam.h index 29eb731..1113f92 100644 --- a/lib/WiFiConnect/WiFiConnectParam.h +++ b/lib/WiFiConnect/WiFiConnectParam.h @@ -1,46 +1,11 @@ -/*! - @file WiFiConnectParam.h - - WiFi Connection Manager with Captive Portal - - Introduction - - This is the documentation for WiFiConnect for the Arduino platform. - It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips. - It contains a captive portal to allow easy connection and changing of WiFi netwoks - via a web based interface and allows for additional user parameters. - It can also display messages via a OLED screen see WiFiConnectOLED class. - - This is a heavily customised version from the original WiFiManager - developed by https://github.com/tzapu . - - Dependencies - - This library depends on - ESP8266 Arduino Core and ESP32 Arduino Core being present on your system. - Please make sure you have installed the latest version before using this library. - - - Written by Stuart Blair. - - License - - GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file. - -*/ -#ifndef WIFI_CONNECT_PARAM -#define WIFI_CONNECT_PARAM +#pragma once #ifndef WiFiConnect_MAX_PARAMS #define WiFiConnect_MAX_PARAMS 10 ///< The maximum size of the param array and how many custom parameters we may have #endif #include -/**************************************************************************/ -/*! - @brief Class that stores a custom parameter -*/ -/**************************************************************************/ + class WiFiConnectParam { public: WiFiConnectParam(const char *custom); @@ -50,19 +15,17 @@ class WiFiConnectParam { const char *getID(); const char *getValue(); const char *getPlaceholder(); - int getValueLength(); + int getValueLength(); const char *getCustomHTML(); void setValue(const char *newValue); private: const char *_id; const char *_placeholder; - char *_value; - int _length; + char *_value; + int _length; const char *_customHTML; void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); friend class WiFiConnect; ///< Declarion for WiFiConnect class - }; -#endif diff --git a/src/NTPupdate.cpp b/src/NTPupdate.cpp index 77c22ce..821772a 100644 --- a/src/NTPupdate.cpp +++ b/src/NTPupdate.cpp @@ -50,7 +50,7 @@ void NTPupdate() { time_t currentTime = getNtpTime(); if (currentTime) { - set_time(currentTime); + set_time(currentTime, Timezone); rtcset = true; NTPupdated = true; radio.rds.ctupdate = false; diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index ba466dd..1d63a45 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -1270,7 +1270,7 @@ void TEF6686::readRDS(byte showrdserrors) { rds.offset = timeoffset; rtcset = true; - if (!NTPupdated) set_time(rdstime + timeoffset); + if (!NTPupdated) set_time(rdstime, timeoffset); } else rds.hasCT = false; lastrdstime = rdstime; lasttimeoffset = timeoffset; diff --git a/src/comms.cpp b/src/comms.cpp index 81b4568..09d5cde 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -967,7 +967,7 @@ void total_pc_control() { if(len < 3 + datalen + 1) break; // Validate buffer size Wire.beginTransmission(addr); - Wire.write(data + 3, len - 3); + Wire.write(data + 3, datalen); auto out = Wire.endTransmission(false); uint8_t recvlen = Wire.requestFrom(addr, data[3+datalen]); @@ -987,7 +987,7 @@ void total_pc_control() { case 4: { // Version Serial.write(2); Serial.write(4); - Serial.write(1); + Serial.write(2); } break; case 5: { // Reboot Serial.write(1); @@ -1006,6 +1006,20 @@ void total_pc_control() { Serial.flush(); Serial.updateBaudRate(clock); } break; + case 7: { // Write to EEPROM + if(len < 4) break; + EEPROM.writeBytes((data[1] << 8) | data[2], data + 3, len - 3); + EEPROM.commit(); + Serial.write(1); + Serial.write(7); + } break; + case 8: { // Read from EEPROM + if(len < 4) break; + auto address = (data[1] << 8) | data[2]; + Serial.write(data[3] + 1); + Serial.write(8); + for(uint16_t i = 0; i < data[3]; i++) Serial.write(EEPROM.read(address + i)); + } break; case 0xff: { // Another wake command Serial.write(1); Serial.write(0xff); diff --git a/src/core.cpp b/src/core.cpp index 5fed322..dd298c8 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -846,7 +846,6 @@ void endMenu() { menuitem = 0; saveData(); if (af == 2) radio.rds.afreg = true; else radio.rds.afreg = false; - Serial.end(); if (wifi) remoteip = IPAddress(WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient); Serial.flush(); diff --git a/src/globals.cpp b/src/globals.cpp index 4c94d8e..3618983 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -217,7 +217,7 @@ int8_t MPold = 0; int8_t USold = 0; int8_t LevelOffset; int8_t LowLevelSet; -int8_t NTPoffset; +int8_t Timezone; int8_t CN; int8_t CNold; RTC_DATA_ATTR int8_t VolSet; diff --git a/src/gui.cpp b/src/gui.cpp index 7e4234f..99c072c 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1393,7 +1393,7 @@ void ShowOneLine(byte position, byte item, bool selected) { FullLineSprite.setTextDatum(TR_DATUM); FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); - FullLineSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset, DEC), 298, 2); + FullLineSprite.drawString((Timezone > -1 ? "+" : "") + String(Timezone), 298, 2); FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false); FullLineSprite.drawString("GMT", 258, 2); break; @@ -2491,7 +2491,7 @@ void ShowOneButton(byte position, byte item, bool selected) { PSSprite.setTextDatum(TL_DATUM); PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); - PSSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset, DEC), 77, 15); + PSSprite.drawString((Timezone > -1 ? "+" : "") + String(Timezone), 77, 15); PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false); PSSprite.setTextDatum(TR_DATUM); PSSprite.drawString("GMT", 73, 15); @@ -4171,11 +4171,11 @@ void MenuUpDown(bool dir) { case ITEM7: if (dir) { - NTPoffset++; - if (NTPoffset > 12) NTPoffset = -12; + Timezone++; + if (Timezone > 12) Timezone = -12; } else { - NTPoffset--; - if (NTPoffset < -12) NTPoffset = 12; + Timezone--; + if (Timezone < -12) Timezone = 12; } OneBigLineSprite.setTextDatum(TR_DATUM); @@ -4183,7 +4183,7 @@ void MenuUpDown(bool dir) { OneBigLineSprite.drawString("GMT", 135, 0); OneBigLineSprite.setTextDatum(TL_DATUM); OneBigLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); - OneBigLineSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset), 155, 0); + OneBigLineSprite.drawString((Timezone > -1 ? "+" : "") + String(Timezone), 155, 0); OneBigLineSprite.pushSprite(24, 118); break; @@ -5225,7 +5225,7 @@ void DoMenu() { wc.addParameter(&XDRGTK_key_input); setWiFiConnectParam = true; } - wc.startConfigurationPortal(AP_WAIT); + wc.startConfigurationPortal(); XDRGTK_key = XDRGTK_key_input.getValue(); EEPROM.writeString(EE_STRING_XDRGTK_KEY, XDRGTK_key); EEPROM.commit(); @@ -5269,7 +5269,7 @@ void DoMenu() { OneBigLineSprite.drawString("GMT", 135, 0); OneBigLineSprite.setTextDatum(TL_DATUM); OneBigLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false); - OneBigLineSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset), 155, 0); + OneBigLineSprite.drawString((Timezone > -1 ? "+" : "") + String(Timezone), 155, 0); OneBigLineSprite.pushSprite(24, 118); break; diff --git a/src/logbook.cpp b/src/logbook.cpp index d75e100..906d6b6 100644 --- a/src/logbook.cpp +++ b/src/logbook.cpp @@ -255,14 +255,14 @@ String getCurrentDateTime(bool inUTC) { int utcOffsetHours = 0; if (!inUTC) { - currentEpoch += (NTPupdated ? NTPoffset * 3600 : radio.rds.offset); // Apply GMT offset if NTPupdated, else RDS offset + currentEpoch += (NTPupdated ? Timezone * 3600 : radio.rds.offset); // Apply GMT offset if NTPupdated, else RDS offset if (NTPupdated && autoDST) { struct tm tempTimeInfo; localtime_r(¤tEpoch, &tempTimeInfo); if (isDST(mktime(&tempTimeInfo))) currentEpoch += 3600; } - } else utcOffsetHours = (NTPupdated ? NTPoffset : radio.rds.offset / 3600); + } else utcOffsetHours = (NTPupdated ? Timezone : radio.rds.offset / 3600); localtime_r(¤tEpoch, &timeInfo); diff --git a/src/nonvolatile.cpp b/src/nonvolatile.cpp index c4e7657..d99cb11 100644 --- a/src/nonvolatile.cpp +++ b/src/nonvolatile.cpp @@ -118,7 +118,7 @@ void saveData() { EEPROM.writeByte(EE_BYTE_MEMPIONLY, mempionly); EEPROM.writeByte(EE_BYTE_MEMDOUBLEPI, memdoublepi); EEPROM.writeByte(EE_BYTE_WAITONLYONSIGNAL, scanholdonsignal); - EEPROM.writeByte(EE_BYTE_NTPOFFSET, NTPoffset); + EEPROM.writeByte(EE_BYTE_TIMEZONE, Timezone); EEPROM.writeByte(EE_BYTE_AUTOLOG, autolog); EEPROM.writeByte(EE_BYTE_AUTODST, autoDST); EEPROM.writeByte(EE_BYTE_CLOCKAMPM, clockampm); @@ -231,7 +231,7 @@ void loadData() { TouchCalData[3] = EEPROM.readUInt(EE_UINT16_CALTOUCH4); TouchCalData[4] = EEPROM.readUInt(EE_UINT16_CALTOUCH5); invertdisplay = EEPROM.readByte(EE_BYTE_INVERTDISPLAY); - NTPoffset = EEPROM.readByte(EE_BYTE_NTPOFFSET); + Timezone = EEPROM.readByte(EE_BYTE_TIMEZONE); autolog = EEPROM.readByte(EE_BYTE_AUTOLOG); autoDST = EEPROM.readByte(EE_BYTE_AUTODST); clockampm = EEPROM.readByte(EE_BYTE_CLOCKAMPM); @@ -338,7 +338,7 @@ void DefaultSettings() { EEPROM.writeUInt(EE_UINT16_CALTOUCH3, 300); EEPROM.writeUInt(EE_UINT16_CALTOUCH4, 3450); EEPROM.writeUInt(EE_UINT16_CALTOUCH5, 3); - EEPROM.writeByte(EE_BYTE_NTPOFFSET, 1); + EEPROM.writeByte(EE_BYTE_TIMEZONE, 0); EEPROM.writeByte(EE_BYTE_AUTOLOG, 1); EEPROM.writeByte(EE_BYTE_AUTODST, 1); EEPROM.writeByte(EE_BYTE_CLOCKAMPM, 0); diff --git a/src/rds.cpp b/src/rds.cpp index d1c481e..1d7f4d2 100644 --- a/src/rds.cpp +++ b/src/rds.cpp @@ -490,8 +490,8 @@ void showCT() { char dateStr[9]; time_t t = rtc.getEpoch(); + t += Timezone * 3600; // Convert offset from hours to seconds if (NTPupdated) { - t += NTPoffset * 3600; // Convert offset from hours to seconds if (autoDST && isDST(t)) t += 3600; } diff --git a/src/rtc.cpp b/src/rtc.cpp index 7d06a11..a731ce0 100644 --- a/src/rtc.cpp +++ b/src/rtc.cpp @@ -1,4 +1,6 @@ #include "rtc.hpp" +#include "globals.h" +#include "nonvolatile.h" // the hardware rtc driver was made with the support of Wh1teRabbitHU's implementation @@ -120,8 +122,14 @@ bool init_rtc() { return false; } -void set_time(time_t time) { +void set_time(time_t time, int8_t offset) { rtc.setTime(time); + if(Timezone != offset) { + EEPROM.writeByte(EE_BYTE_TIMEZONE, offset); + EEPROM.commit(); + Timezone = offset; + } + if(!rx_rtc_avail) return; struct tm* timeinfo = gmtime(&time); writeToModule(0x1F, 64);