ayushsharma82 / ElegantOTA

OTA updates made slick and simple for everyone!
https://elegantota.pro
GNU Affero General Public License v3.0
643 stars 119 forks source link

Webserver fails to connect afer one OTA upload #209

Closed Fyfth closed 4 months ago

Fyfth commented 4 months ago

ESP 32 C6

Code: /*

ElegantOTA - Demo Example

Skill Level: Beginner

This example provides with a bare minimal app with ElegantOTA functionality.

Github: https://github.com/ayushsharma82/ElegantOTA WiKi: https://docs.elegantota.pro

Works with following hardware:

*/

if defined(ESP8266)

include

include

include

elif defined(ESP32)

include

include

include

elif defined(TARGET_RP2040)

include

include

endif

include

const char ssid = "1"; const char password = "12345678"; int S1= 4; int S2=5;

if defined(ESP8266)

ESP8266WebServer server(80);

elif defined(ESP32)

WebServer server(80);

elif defined(TARGET_RP2040)

WebServer server(80);

endif

unsigned long ota_progress_millis = 0;

void onOTAStart() { // Log when OTA has started Serial.println("OTA update started!"); // }

void onOTAProgress(size_t current, size_t final) { // Log every 1 second if (millis() - ota_progress_millis > 1000) { ota_progress_millis = millis(); Serial.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final); } }

void onOTAEnd(bool success) { // Log when OTA has finished if (success) { Serial.println("OTA update finished successfully!"); } else { Serial.println("There was an error during OTA update!"); } // }

void setup(void) { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); pinMode(S1, OUTPUT); pinMode(S2,OUTPUT);

// Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP());

server.on("/", []() { server.send(200, "text/plain", "Hi! This is ElegantOTA Demo."); });

ElegantOTA.begin(&server); // Start ElegantOTA // ElegantOTA callbacks ElegantOTA.onStart(onOTAStart); ElegantOTA.onProgress(onOTAProgress); ElegantOTA.onEnd(onOTAEnd);

server.begin(); Serial.println("HTTP server started"); }

void loop(void) { server.handleClient(); ElegantOTA.loop(); for (int i = 0; i <= 3; i++) { digitalWrite(S1, HIGH);// Solenoid is effective digitalWrite(S2, LOW);// Solenoid is effective delay(350); digitalWrite(S1, LOW);// Solenoid is effective digitalWrite(S2, HIGH);// Solenoid is effective delay(400); digitalWrite(S1, HIGH);// Solenoid is effective digitalWrite(S2, LOW);// Solenoid is effective delay(350); digitalWrite(S1, LOW);// Solenoid is effective digitalWrite(S2, HIGH);// Solenoid is effective delay(400); } digitalWrite(S1, LOW);// Solenoid is effective digitalWrite(S2, LOW);// Solenoid is effective

for(;;);

}

ayushsharma82 commented 4 months ago
  1. There's an infinite for loop for(;;); in your code.
  2. Have you tried ElegantOTA bare example without any modifications? If that works well, then it's probably something in your code messing up WiFi connections. Honestly, ElegantOTA doesn't have anything to do with WiFi connection.
  3. You can try using NetWizard - It will handle the WiFi connections and setup for you.
Fyfth commented 4 months ago

Thanks! I figured it out. The problem was the for(;;) Thx

On Fri, Jul 19, 2024 at 14:06 Ayush Sharma @.***> wrote:

  1. There's an infinite for loop for(;;); in your code.
  2. Have you tried ElegantOTA bare example without any modifications? If that works well, then it's probably something in your code messing up WiFi connections. Honestly, ElegantOTA doesn't have anything to do with WiFi connection.
  3. You can try using NetWizard https://github.com/ayushsharma82/NetWizard - It will handle the WiFi connections and setup for you.

— Reply to this email directly, view it on GitHub https://github.com/ayushsharma82/ElegantOTA/issues/209#issuecomment-2239830107, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2CKBGVHJTWBSYLYOHRYOOLZNFISZAVCNFSM6AAAAABLE3JYASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZZHAZTAMJQG4 . You are receiving this because you authored the thread.Message ID: @.***>