From 9d201f19985f1df4befe632efa9bf91caf687111 Mon Sep 17 00:00:00 2001 From: Dakkaron Date: Sat, 11 Jan 2025 22:53:25 +0100 Subject: [PATCH] Allowed for max 3 wifi networks, downloadFile() --- T-HMI-PEPmonitor/src/constants.h | 2 + T-HMI-PEPmonitor/src/hardware/sdHandler.cpp | 4 + T-HMI-PEPmonitor/src/hardware/wifiHandler.cpp | 90 ++++++++++++++----- T-HMI-PEPmonitor/src/hardware/wifiHandler.h | 3 + T-HMI-PEPmonitor/src/systemconfig.h | 4 + 5 files changed, 80 insertions(+), 23 deletions(-) diff --git a/T-HMI-PEPmonitor/src/constants.h b/T-HMI-PEPmonitor/src/constants.h index 01886fa..965ee23 100644 --- a/T-HMI-PEPmonitor/src/constants.h +++ b/T-HMI-PEPmonitor/src/constants.h @@ -48,6 +48,8 @@ #define INHALATION_TASK_WARN_TIMEOUT 10000L #define INHALATION_TASK_END_TIMEOUT 15000L +#define MAX_WIFI_NETWORKS 3 + #define GAME_SELECTION_POWEROFF_TIMEOUT 3L*60L*1000L // Power off device if it spends >3 minutes on game selection screen #define WIN_SCREEN_TIMEOUT 3L*60L*1000L diff --git a/T-HMI-PEPmonitor/src/hardware/sdHandler.cpp b/T-HMI-PEPmonitor/src/hardware/sdHandler.cpp index 243121c..046f80a 100644 --- a/T-HMI-PEPmonitor/src/hardware/sdHandler.cpp +++ b/T-HMI-PEPmonitor/src/hardware/sdHandler.cpp @@ -35,6 +35,10 @@ void readSystemConfig(SystemConfig* systemConfig, String* errorMessage) { getIniSection(SYSTEM_CONFIG_INI_PATH, "[system]", resBuffer, 1024, errorMessage); systemConfig->wifiSsid = getIniValueFromSection(resBuffer, "wifiSSID", &ignoreErrors); systemConfig->wifiPassword = getIniValueFromSection(resBuffer, "wifiPassword", &ignoreErrors); + systemConfig->wifiSsid2 = getIniValueFromSection(resBuffer, "wifiSSID2", &ignoreErrors); + systemConfig->wifiPassword2 = getIniValueFromSection(resBuffer, "wifiPassword2", &ignoreErrors); + systemConfig->wifiSsid3 = getIniValueFromSection(resBuffer, "wifiSSID3", &ignoreErrors); + systemConfig->wifiPassword3 = getIniValueFromSection(resBuffer, "wifiPassword3", &ignoreErrors); systemConfig->trampolineIp = getIniValueFromSection(resBuffer, "trampolineIp", &ignoreErrors); systemConfig->touchScreenZThreshold = 2.5*(100-atoi(getIniValueFromSection(resBuffer, "touchScreenSensitivity", &ignoreErrors).c_str())); systemConfig->simulateTrampoline = stringIsTrue(getIniValueFromSection(resBuffer, "simulateTrampoline", &ignoreErrors), false); diff --git a/T-HMI-PEPmonitor/src/hardware/wifiHandler.cpp b/T-HMI-PEPmonitor/src/hardware/wifiHandler.cpp index b4032af..ad450b7 100644 --- a/T-HMI-PEPmonitor/src/hardware/wifiHandler.cpp +++ b/T-HMI-PEPmonitor/src/hardware/wifiHandler.cpp @@ -10,32 +10,47 @@ uint8_t startWifi() { if (wifiConnected) { return CONNECTION_OK; } - Serial.println("Starting WIFI"); - WiFi.mode(WIFI_STA); - ssid = systemConfig.wifiSsid; - password = systemConfig.wifiPassword; - trampolineIp = systemConfig.trampolineIp; - Serial.println(ssid); - Serial.println(password); - Serial.println(trampolineIp); - WiFi.begin(ssid, password); - Serial.print("Connecting to WIFI"); - for (uint8_t i=0;iavailable(); + stream->readBytes(fileBuffer, FILE_SIZE); + if (availableDataSize > 0) { + stream->readBytes(bufferPointer, availableDataSize); + downloadedDataSize += availableDataSize; + bufferPointer += availableDataSize; + } + } + Serial.println("Downloaded file"); + File file = SD_MMC.open(filename, FILE_WRITE, true); + file.write(fileBuffer, FILE_SIZE); + delete[] (fileBuffer); } \ No newline at end of file diff --git a/T-HMI-PEPmonitor/src/hardware/wifiHandler.h b/T-HMI-PEPmonitor/src/hardware/wifiHandler.h index 1cdee64..5e149cc 100644 --- a/T-HMI-PEPmonitor/src/hardware/wifiHandler.h +++ b/T-HMI-PEPmonitor/src/hardware/wifiHandler.h @@ -21,6 +21,9 @@ void getJumpData(JumpData* jumpData); bool startFetchingNTPTime(); void getNTPTime(String* ntpDateString, String* ntpTimeString, String* errorMessage); +void downloadFile(String url, String filename, String* errorMessage); + +uint8_t startWifi(); #endif /* __WIFI_HANDLER_H__ */ \ No newline at end of file diff --git a/T-HMI-PEPmonitor/src/systemconfig.h b/T-HMI-PEPmonitor/src/systemconfig.h index 9f3b46b..495f530 100644 --- a/T-HMI-PEPmonitor/src/systemconfig.h +++ b/T-HMI-PEPmonitor/src/systemconfig.h @@ -7,6 +7,10 @@ struct SystemConfig { String trampolineIp; String wifiSsid; String wifiPassword; + String wifiSsid2; + String wifiPassword2; + String wifiSsid3; + String wifiPassword3; uint8_t touchScreenZThreshold; bool simulateTrampoline; bool simulateBlows;