diff --git a/src/BootstrapManager.cpp b/src/BootstrapManager.cpp index 23b826c..fd16622 100644 --- a/src/BootstrapManager.cpp +++ b/src/BootstrapManager.cpp @@ -51,7 +51,11 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man launchWebServerForOTAConfig(); } #if defined(ARDUINO_ARCH_ESP32) - esp_task_wdt_init(3000, true); //enable panic so ESP32 restarts + esp_task_wdt_config_t twdt_config = { + .timeout_ms = 5000, + .trigger_panic = true, + }; + esp_task_wdt_init(&twdt_config); //enable panic so ESP32 restarts esp_task_wdt_add(NULL); //add current thread to WDT watch #endif #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 @@ -110,7 +114,11 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man #endif } #if defined(ARDUINO_ARCH_ESP32) - esp_task_wdt_init(3000, true); //enable panic so ESP32 restarts + esp_task_wdt_config_t twdt_config = { + .timeout_ms = 3000, // TODO 3000 + .trigger_panic = true, + }; + esp_task_wdt_init(&twdt_config); //enable panic so ESP32 restarts esp_task_wdt_add(NULL); //add current thread to WDT watch #endif #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 diff --git a/src/EthManager.cpp b/src/EthManager.cpp index 41dcbd3..b17b620 100644 --- a/src/EthManager.cpp +++ b/src/EthManager.cpp @@ -27,9 +27,9 @@ const ethernet_config ethernetDevices[] = { // No Ethernet { }, +#if CONFIG_IDF_TARGET_ESP32 // QuinLed-ESP32-Ethernet { - 0, 5, 23, @@ -102,6 +102,11 @@ const ethernet_config ethernetDevices[] = { ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_OUT } +#endif +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) + +#endif + }; /** @@ -109,14 +114,18 @@ const ethernet_config ethernetDevices[] = { * @param deviceNumber to use */ void EthManager::connectToEthernet(int8_t deviceNumber) { +#if CONFIG_IDF_TARGET_ESP32 ETH.begin( + ethernetDevices[deviceNumber].type, ethernetDevices[deviceNumber].address, - ethernetDevices[deviceNumber].power, ethernetDevices[deviceNumber].mdc, ethernetDevices[deviceNumber].mdio, - ethernetDevices[deviceNumber].type, + ethernetDevices[deviceNumber].power, ethernetDevices[deviceNumber].clk_mode ); +#else + // TODO fix this +#endif } /** @@ -124,17 +133,14 @@ void EthManager::connectToEthernet(int8_t deviceNumber) { * @param deviceNumber to deallocate */ void EthManager::deallocateEthernetPins(int8_t deviceNumber) { - const uint32_t MATRIX_DETACH_OUT_SIG = 0x100; - gpio_matrix_out(ethernetDevices[deviceNumber].address, MATRIX_DETACH_OUT_SIG, false, false); - gpio_matrix_out(ethernetDevices[deviceNumber].power, MATRIX_DETACH_OUT_SIG, false, false); - gpio_matrix_out(ethernetDevices[deviceNumber].mdc, MATRIX_DETACH_OUT_SIG, false, false); - gpio_matrix_out(ethernetDevices[deviceNumber].mdio, MATRIX_DETACH_OUT_SIG, false, false); - gpio_matrix_out(ethernetDevices[deviceNumber].clk_mode, MATRIX_DETACH_OUT_SIG, false, false); - pinMode(ethernetDevices[deviceNumber].address, INPUT); - pinMode(ethernetDevices[deviceNumber].power, INPUT); - pinMode(ethernetDevices[deviceNumber].mdc, INPUT); - pinMode(ethernetDevices[deviceNumber].mdio, INPUT); - pinMode(ethernetDevices[deviceNumber].clk_mode, INPUT); + gpio_reset_pin((gpio_num_t) ethernetDevices[deviceNumber].address); + gpio_reset_pin((gpio_num_t) ethernetDevices[deviceNumber].power); + gpio_reset_pin((gpio_num_t) ethernetDevices[deviceNumber].mdc); + gpio_reset_pin((gpio_num_t) ethernetDevices[deviceNumber].mdio); +#if CONFIG_IDF_TARGET_ESP32 + gpio_reset_pin((gpio_num_t) ethernetDevices[deviceNumber].clk_mode); +#endif + delay(1); } #endif diff --git a/src/EthManager.h b/src/EthManager.h index 80f864c..ac20704 100644 --- a/src/EthManager.h +++ b/src/EthManager.h @@ -34,8 +34,10 @@ typedef struct EthConfig { int power; int mdc; int mdio; +#if CONFIG_IDF_TARGET_ESP32 eth_phy_type_t type; eth_clock_mode_t clk_mode; +#endif } ethernet_config; extern const ethernet_config ethernetDevices[]; diff --git a/src/WifiManager.cpp b/src/WifiManager.cpp index f1a904c..15eca78 100644 --- a/src/WifiManager.cpp +++ b/src/WifiManager.cpp @@ -70,7 +70,7 @@ void WifiManager::setupWiFi(void (*manageDisconnections)(), void (*manageHardwar #if defined(ESP8266) WiFi.setSleepMode(WIFI_NONE_SLEEP); #endif - WiFi.setAutoConnect(true); +// WiFi.setAutoConnect(true); // TODO WiFi.setAutoReconnect(true); Serial.println(microcontrollerIP); if (!microcontrollerIP.equals("DHCP")) { @@ -109,7 +109,9 @@ void WifiManager::setupWiFi(void (*manageDisconnections)(), void (*manageHardwar }); #elif defined(ARDUINO_ARCH_ESP32) WiFi.setHostname(helper.string2char(deviceName)); +#if !CONFIG_IDF_TARGET_ESP32S2 btStop(); +#endif #endif // Start wifi connection WiFi.begin(qsid.c_str(), qpass.c_str()); @@ -224,6 +226,9 @@ void WifiManager::setupOTAUpload() { Serial.println(F("End")); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { +#if defined(ARDUINO_ARCH_ESP32) + esp_task_wdt_reset(); // TODO +# endif Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) { @@ -693,6 +698,7 @@ void WifiManager::parseWiFiCommand(char *rpcData) { sendImprovStateResponse(0x03, false); //provisioning improvActive = 2; JsonDocument doc; + bool connected = isConnected(); String devName = String(random(0, 90000)); doc["deviceName"] = String(DEVICE_NAME) + "_" + devName; doc["microcontrollerIP"] = "DHCP"; @@ -704,7 +710,6 @@ void WifiManager::parseWiFiCommand(char *rpcData) { doc["mqttuser"] = ""; doc["mqttpass"] = ""; additionalParam = "2"; - Serial.println(F("Saving setup.json")); File jsonFile = LittleFS.open("/setup.json", FILE_WRITE); if (!jsonFile) { Serial.println("Failed to open [setup.json] file for writing"); @@ -712,17 +717,19 @@ void WifiManager::parseWiFiCommand(char *rpcData) { serializeJsonPretty(doc, Serial); serializeJson(doc, jsonFile); jsonFile.close(); + if (connected) { + IPAddress localIP = WiFi.localIP(); + Serial.printf("IMPROV http://%d.%d.%d.%d\n", localIP[0], localIP[1], localIP[2], localIP[3]); + } } #if defined(ARDUINO_ARCH_ESP32) WiFi.disconnect(); WiFi.begin(clientSSID, clientPass); while (!isConnected()) {} #endif - delay(DELAY_200); sendImprovRPCResponse(ImprovRPCType::Request_State); - delay(DELAY_200); sendImprovStateResponse(0x04, false); - delay(DELAY_200); + Serial.flush(); #if defined(ARDUINO_ARCH_ESP32) ESP.restart(); #elif defined(ESP8266) diff --git a/src/WifiManager.h b/src/WifiManager.h index a3d5e43..94ea634 100644 --- a/src/WifiManager.h +++ b/src/WifiManager.h @@ -33,6 +33,7 @@ #include #include #include +#include #endif