mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Add MD5 to core, Fix OTA examples and Digest Authentication to OTA and espota.py
This commit is contained in:
@ -6,26 +6,36 @@
|
||||
const char* ssid = "...";
|
||||
const char* password = "...";
|
||||
|
||||
ArduinoOTA ota_server;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Booting");
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
/* try the flash stored password first */
|
||||
WiFi.begin();
|
||||
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED){
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.println("Retrying connection...");
|
||||
Serial.begin(115200);
|
||||
Serial.println("Booting");
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED){
|
||||
Serial.println("Connection Failed! Rebooting...");
|
||||
delay(5000);
|
||||
ESP.reset();
|
||||
}
|
||||
ota_server.setup();
|
||||
//ArduinoOTA.setPort(8266);//Defaults to 8266
|
||||
//ArduinoOTA.setHostname((const char *)"myesp8266");//Defaults to esp8266-[ChipID]
|
||||
//ArduinoOTA.setPassword((const char *)"123");//defaults to no authentication
|
||||
ArduinoOTA.onStart([]() { Serial.println("Start"); });
|
||||
ArduinoOTA.onEnd([]() { Serial.println("End"); });
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\n", (progress/(total/100)));
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if(error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if(error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if(error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if(error == OTA_RECIEVE_ERROR) Serial.println("Recieve Failed");
|
||||
else if(error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
Serial.println("Ready");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
ota_server.handle();
|
||||
yield();
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
Reference in New Issue
Block a user