123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #if A_OTA==1
- void setupOta(char *hostname) {
- ArduinoOTA.begin();
- #if _DUSB>=1
- Serial.println(F("setupOta:: Started"));
- #endif
-
- ArduinoOTA.setHostname(hostname);
-
- ArduinoOTA.onStart([]() {
- String type;
-
-
-
- type = "sketch";
-
-
-
- Serial.println("Start updating " + type);
- });
-
- ArduinoOTA.onEnd([]() {
- Serial.println("\nEnd");
- });
-
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("Progress: %u%%\r", (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_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- });
-
- #if _DUSB>=1
- Serial.println("Ready");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- #endif
-
-
- #if A_SERVER==2
- ESPhttpUpdate.rebootOnUpdate(false);
-
- server.on("/esp", HTTP_POST, [&](){
-
- HTTPUpdateResult ret = ESPhttpUpdate.update(server.arg("firmware"), "1.0.0");
-
- switch(ret) {
- case HTTP_UPDATE_FAILED:
-
- Serial.println(F("Update failed"));
- break;
- case HTTP_UPDATE_NO_UPDATES:
-
- Serial.println(F("Update not necessary"));
- break;
- case HTTP_UPDATE_OK:
-
- Serial.println(F("Update started"));
- ESP.restart();
- break;
- default:
- Serial.println(F("setupOta:: Unknown ret="));
- }
- });
- #endif
- }
- void updateOtaa() {
- String response="";
- Serial.print(F("updateOtaa:: <unimplemented> IP="));
- printIP((IPAddress)WiFi.localIP(),'.',response);
- Serial.println(response);
-
- }
- #endif
|