Skip to content

Commit fa1716e

Browse files
authored
Add Ota and mdns (espressif#257)
* Add Sketch Update Library * Add MDNS Library * Add Arduino OTA Library * add missing library file * Add library files for Update * Add missing headers * fix ota command * Add espota binary * remove bad example * PlatformIO does not auto forward declare methods like Arduino Builder
1 parent 2f5efed commit fa1716e

27 files changed

+2428
-91
lines changed

Diff for: libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <WiFi.h>
2+
#include <ESPmDNS.h>
3+
#include <WiFiUdp.h>
4+
#include <ArduinoOTA.h>
5+
6+
const char* ssid = "..........";
7+
const char* password = "..........";
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
Serial.println("Booting");
12+
WiFi.mode(WIFI_STA);
13+
WiFi.begin(ssid, password);
14+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
15+
Serial.println("Connection Failed! Rebooting...");
16+
delay(5000);
17+
ESP.restart();
18+
}
19+
20+
// Port defaults to 3232
21+
// ArduinoOTA.setPort(3232);
22+
23+
// Hostname defaults to esp3232-[MAC]
24+
// ArduinoOTA.setHostname("myesp32");
25+
26+
// No authentication by default
27+
// ArduinoOTA.setPassword("admin");
28+
29+
// Password can be set with it's md5 value as well
30+
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
31+
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
32+
33+
ArduinoOTA.onStart([]() {
34+
String type;
35+
if (ArduinoOTA.getCommand() == U_FLASH)
36+
type = "sketch";
37+
else // U_SPIFFS
38+
type = "filesystem";
39+
40+
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
41+
Serial.println("Start updating " + type);
42+
});
43+
ArduinoOTA.onEnd([]() {
44+
Serial.println("\nEnd");
45+
});
46+
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
47+
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
48+
});
49+
ArduinoOTA.onError([](ota_error_t error) {
50+
Serial.printf("Error[%u]: ", error);
51+
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
52+
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
53+
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
54+
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
55+
else if (error == OTA_END_ERROR) Serial.println("End Failed");
56+
});
57+
ArduinoOTA.begin();
58+
Serial.println("Ready");
59+
Serial.print("IP address: ");
60+
Serial.println(WiFi.localIP());
61+
}
62+
63+
void loop() {
64+
ArduinoOTA.handle();
65+
}

Diff for: libraries/ArduinoOTA/keywords.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#######################################
2+
# Syntax Coloring Map For Ultrasound
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
ArduinoOTA KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
begin KEYWORD2
16+
setup KEYWORD2
17+
handle KEYWORD2
18+
onStart KEYWORD2
19+
onEnd KEYWORD2
20+
onError KEYWORD2
21+
onProgress KEYWORD2
22+
23+
#######################################
24+
# Constants (LITERAL1)
25+
#######################################
26+

Diff for: libraries/ArduinoOTA/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ArduinoOTA
2+
version=1.0
3+
author=Ivan Grokhotkov and Hristo Gochkov
4+
maintainer=Hristo Gochkov <hristo@espressif.com>
5+
sentence=Enables Over The Air upgrades, via wifi and espota.py UDP request/TCP download.
6+
paragraph=With this library you can enable your sketch to be upgraded over network. Includes mdns anounces to get discovered by the arduino IDE.
7+
category=Communication
8+
url=
9+
architectures=esp32

0 commit comments

Comments
 (0)