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 <HTTPUpdate.h>
|
||||
|
||||
|
||||
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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
25
src/main.cpp
25
src/main.cpp
@@ -26,6 +26,7 @@
|
||||
#include <fetchOTA.h>
|
||||
#include <ESP32Ping.h>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user