diff --git a/documentation/old.md b/documentation/old.md new file mode 100644 index 0000000..ea6f346 --- /dev/null +++ b/documentation/old.md @@ -0,0 +1,38 @@ +extern "C" { + #include "lwip/netif.h" +} + +void listNetworkInterfaces() { + esp_netif_t *netif = NULL; + Serial.println("\n=== Listing Network Interfaces ==="); + + for (netif = esp_netif_next(NULL); netif != NULL; netif = esp_netif_next(netif)) { + const char* if_key = esp_netif_get_ifkey(netif); + const char* if_desc = esp_netif_get_desc(netif); + + Serial.printf("Interface Key: %s\n", if_key); + Serial.printf("Description : %s\n", if_desc); + Serial.println("-----------------------------"); + } +} + +void setEthernetAsDefault() { + Log.verbose("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + listNetworkInterfaces(); + // Attempt to locate the Ethernet network interface. + // (The name may vary—on some systems it might be "eth0") + esp_netif_t* netif = esp_netif_get_handle_from_ifkey("ETH_DEF"); + + if (netif) { + Serial.println("Netif handle obtained successfully."); + } else { + Serial.println("Failed to obtain netif handle."); + } + struct netif *eth_netif2 = netif_find("ETH_DEF"); + if (netif) { + netif_set_default(eth_netif2); + Log.verbose("Ethernet set as default network interface."); + } else { + Log.verbose("Could not find Ethernet netif."); + } +} \ No newline at end of file diff --git a/lib/fetchOTA/fetchOTA.cpp b/lib/fetchOTA/fetchOTA.cpp index fed3703..1d6cb8a 100644 --- a/lib/fetchOTA/fetchOTA.cpp +++ b/lib/fetchOTA/fetchOTA.cpp @@ -9,6 +9,7 @@ #include #include + OTA::OTA(String server_url, Version currentVersion, String currentDeviceConfiguration) { _serverUrl = server_url; _currentVersion = currentVersion; @@ -21,6 +22,7 @@ Firmware OTA::getLatestVersionOnServer() { HTTPClient http; http.begin(_serverUrl); int httpCode = http.GET(); + Log.verbose("HTTP Code: %d", httpCode); if (httpCode != 200) { return createErrorResponse("HTTP GET request failed with code " + String(httpCode)); diff --git a/platformio.ini b/platformio.ini index 7b7b81e..669ba02 100644 --- a/platformio.ini +++ b/platformio.ini @@ -25,7 +25,7 @@ lib_deps = ESP32Ping board_build.partitions = default.csv upload_protocol = espota -upload_port = 192.168.5.181 +upload_port = 192.168.5.180 build_flags = -Wall -Wextra [env:ESP32_INA226] @@ -41,11 +41,12 @@ lib_deps = ESP32Ping board_build.partitions = default.csv upload_protocol = espota -upload_port = 192.168.5.181 +upload_port = 192.168.5.181 build_flags = -Wall -Wextra -DUSE_INA226 [env:native] platform = native build_flags = -DUNIT_TEST -Ilib/fetchOTA/ lib_deps = - fetchOTA + fetchOTA + arduino-libraries/ArduinoHttpClient@^0.6.1 diff --git a/src/global_data/defines.h b/src/global_data/defines.h index 13d6ce3..05f9bf8 100644 --- a/src/global_data/defines.h +++ b/src/global_data/defines.h @@ -7,7 +7,7 @@ #define water_level_min_key "water_level_min" #define water_level_max_key "water_level_max" #define water_volume_key "water_volume" -#define current_software_version Version{0, 0, 17} +#define current_software_version Version{0, 0, 18} #define REQUIRED_SPIFFS_VERSION Version{5, 0, 0} #define RESISTOR_VALUE 4 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0fb75b0..4bacb8c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,7 @@ #include #include + Preferences prefs; extern WaterData water_data; @@ -209,9 +210,22 @@ void setup() digitalWrite(LED_RED, 0); xTaskCreate(ethernet_task, "EthernetTask", 4096, NULL, 1, NULL); + delay(1000); + bool started = false; + if (ETH.linkUp()){ + xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL); + started = true; + } xTaskCreate(wifi_task, "WiFiTask", 10000, NULL, 1, NULL); - delay(250); + delay(2000); + + if (!started) { + xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL); + } + + + Log.verbose("Starting webserver"); server.begin(); @@ -235,15 +249,14 @@ void setup() } else { Log.verbose("No WiFi or Ethernet connection, retrying..."); } - delay(200); // Delay to prevent rapid retry + delay(1000); // Delay to prevent rapid retry } - xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL); + } + void loop() { ArduinoOTA.handle(); delay(1000); -} - - +} \ No newline at end of file diff --git a/src/tools/tools.cpp b/src/tools/tools.cpp index 14f61db..91094cc 100644 --- a/src/tools/tools.cpp +++ b/src/tools/tools.cpp @@ -81,6 +81,7 @@ void check_update_task(void* parameter) { OTA ota("https://iot.tobiasmaier.me/firmware/waterlevel", current_software_version, "INA233"); #endif OTA spiffs_fs("https://iot.tobiasmaier.me/filesystem/waterlevel", REQUIRED_SPIFFS_VERSION, "generic"); + // Init SPIFFS update and check for update // If there is a SPIFSS update it will be ran automatically, as SPIFFS is necessary for the firmware to run @@ -139,11 +140,12 @@ void run_ota_update_task(void* parameter) { void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { -if (type == WS_EVT_CONNECT) { -Serial.println("WebSocket client connected"); -} else if (type == WS_EVT_DISCONNECT) { -Serial.println("WebSocket client disconnected"); -} else if (type == WS_EVT_DATA) { -// Optionally process data received from the client -} + if (type == WS_EVT_CONNECT) { + Serial.println("WebSocket client connected"); + } else if (type == WS_EVT_DISCONNECT) { + Serial.println("WebSocket client disconnected"); + } else if (type == WS_EVT_DATA) { + // Optionally process data received from the client + } } +