Fixed OTA Ethernet bug
All checks were successful
Test compiling project / test (push) Successful in 2m28s
All checks were successful
Test compiling project / test (push) Successful in 2m28s
This commit is contained in:
38
documentation/old.md
Normal file
38
documentation/old.md
Normal file
@@ -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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <ArduinoLog.h>
|
#include <ArduinoLog.h>
|
||||||
#include <HTTPUpdate.h>
|
#include <HTTPUpdate.h>
|
||||||
|
|
||||||
|
|
||||||
OTA::OTA(String server_url, Version currentVersion, String currentDeviceConfiguration) {
|
OTA::OTA(String server_url, Version currentVersion, String currentDeviceConfiguration) {
|
||||||
_serverUrl = server_url;
|
_serverUrl = server_url;
|
||||||
_currentVersion = currentVersion;
|
_currentVersion = currentVersion;
|
||||||
@@ -21,6 +22,7 @@ Firmware OTA::getLatestVersionOnServer() {
|
|||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.begin(_serverUrl);
|
http.begin(_serverUrl);
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
|
Log.verbose("HTTP Code: %d", httpCode);
|
||||||
|
|
||||||
if (httpCode != 200) {
|
if (httpCode != 200) {
|
||||||
return createErrorResponse("HTTP GET request failed with code " + String(httpCode));
|
return createErrorResponse("HTTP GET request failed with code " + String(httpCode));
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ lib_deps =
|
|||||||
ESP32Ping
|
ESP32Ping
|
||||||
board_build.partitions = default.csv
|
board_build.partitions = default.csv
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.5.181
|
upload_port = 192.168.5.180
|
||||||
build_flags = -Wall -Wextra
|
build_flags = -Wall -Wextra
|
||||||
|
|
||||||
[env:ESP32_INA226]
|
[env:ESP32_INA226]
|
||||||
@@ -49,3 +49,4 @@ platform = native
|
|||||||
build_flags = -DUNIT_TEST -Ilib/fetchOTA/
|
build_flags = -DUNIT_TEST -Ilib/fetchOTA/
|
||||||
lib_deps =
|
lib_deps =
|
||||||
fetchOTA
|
fetchOTA
|
||||||
|
arduino-libraries/ArduinoHttpClient@^0.6.1
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define water_level_min_key "water_level_min"
|
#define water_level_min_key "water_level_min"
|
||||||
#define water_level_max_key "water_level_max"
|
#define water_level_max_key "water_level_max"
|
||||||
#define water_volume_key "water_volume"
|
#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 REQUIRED_SPIFFS_VERSION Version{5, 0, 0}
|
||||||
|
|
||||||
#define RESISTOR_VALUE 4
|
#define RESISTOR_VALUE 4
|
||||||
23
src/main.cpp
23
src/main.cpp
@@ -26,6 +26,7 @@
|
|||||||
#include <fetchOTA.h>
|
#include <fetchOTA.h>
|
||||||
#include <ESP32Ping.h>
|
#include <ESP32Ping.h>
|
||||||
|
|
||||||
|
|
||||||
Preferences prefs;
|
Preferences prefs;
|
||||||
|
|
||||||
extern WaterData water_data;
|
extern WaterData water_data;
|
||||||
@@ -209,9 +210,22 @@ void setup()
|
|||||||
digitalWrite(LED_RED, 0);
|
digitalWrite(LED_RED, 0);
|
||||||
|
|
||||||
xTaskCreate(ethernet_task, "EthernetTask", 4096, NULL, 1, NULL);
|
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);
|
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");
|
Log.verbose("Starting webserver");
|
||||||
server.begin();
|
server.begin();
|
||||||
@@ -235,15 +249,14 @@ void setup()
|
|||||||
} else {
|
} else {
|
||||||
Log.verbose("No WiFi or Ethernet connection, retrying...");
|
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()
|
void loop()
|
||||||
{
|
{
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ void check_update_task(void* parameter) {
|
|||||||
#endif
|
#endif
|
||||||
OTA spiffs_fs("https://iot.tobiasmaier.me/filesystem/waterlevel", REQUIRED_SPIFFS_VERSION, "generic");
|
OTA spiffs_fs("https://iot.tobiasmaier.me/filesystem/waterlevel", REQUIRED_SPIFFS_VERSION, "generic");
|
||||||
|
|
||||||
|
|
||||||
// Init SPIFFS update and check for update
|
// 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
|
// If there is a SPIFSS update it will be ran automatically, as SPIFFS is necessary for the firmware to run
|
||||||
Firmware latest_spiff_version = spiffs_fs.getLatestVersionOnServer();
|
Firmware latest_spiff_version = spiffs_fs.getLatestVersionOnServer();
|
||||||
@@ -147,3 +148,4 @@ Serial.println("WebSocket client disconnected");
|
|||||||
// Optionally process data received from the client
|
// Optionally process data received from the client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user