1
0
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:
Me No Dev
2015-11-09 00:42:30 +02:00
parent e613e42249
commit a8976a01fd
13 changed files with 518 additions and 247 deletions

View File

@ -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();
}

View File

@ -5,9 +5,7 @@
const char* ssid = "...";
const char* password = "...";
const char* host_prefix = "OTA-LEDS-";
ArduinoOTA ota_server(host_prefix, 8266, /* debug_serial= */ true);
const char* host = "OTA-LEDS";
int led_pin = 13;
#define N_DIMMERS 3
@ -23,8 +21,7 @@ void setup() {
Serial.println("Booting");
WiFi.mode(WIFI_STA);
/* try the flash stored password first */
WiFi.begin();
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED){
WiFi.begin(ssid, password);
@ -33,10 +30,6 @@ void setup() {
/* switch off led */
digitalWrite(led_pin, HIGH);
/* setup the OTA server */
ota_server.setup();
Serial.println("Ready");
/* configure dimmers, and OTA server events */
analogWriteRange(1000);
analogWrite(led_pin,990);
@ -47,13 +40,14 @@ void setup() {
analogWrite(dimmer_pin[i],50);
}
ota_server.onStart([]() { // switch off all the PWMs during upgrade
ArduinoOTA.setHostname(host);
ArduinoOTA.onStart([]() { // switch off all the PWMs during upgrade
for(int i=0; i<N_DIMMERS;i++)
analogWrite(dimmer_pin[i], 0);
analogWrite(led_pin,0);
});
ota_server.onEnd([]() { // do a fancy thing with our board led at end
ArduinoOTA.onEnd([]() { // do a fancy thing with our board led at end
for (int i=0;i<30;i++)
{
analogWrite(led_pin,(i*100) % 1001);
@ -61,11 +55,14 @@ void setup() {
}
});
ota_server.onError([]() { ESP.restart(); });
ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); });
/* setup the OTA server */
ArduinoOTA.begin();
Serial.println("Ready");
}
void loop() {
ota_server.handle();
yield();
ArduinoOTA.handle();
}