-
Notifications
You must be signed in to change notification settings - Fork 1
/
ota_wifi_blink.ino
60 lines (52 loc) · 2.01 KB
/
ota_wifi_blink.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println("Iniciando...");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Conexao falhou! Reiniciando...");
delay(5000);
ESP.restart();
}
// Porta padrao do ESP8266 para OTA eh 8266 - Voce pode mudar ser quiser, mas deixe indicado!
// ArduinoOTA.setPort(8266);
// O Hostname padrao eh esp8266-[ChipID], mas voce pode mudar com essa funcao
// ArduinoOTA.setHostname("nome_do_meu_esp8266");
// Nenhuma senha eh pedida, mas voce pode dar mais seguranca pedindo uma senha pra gravar
// ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.onStart([]() {
Serial.println("Inicio...");
});
ArduinoOTA.onEnd([]() {
Serial.println("nFim!");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progresso: %u%%r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Erro [%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Autenticacao Falhou");
else if (error == OTA_BEGIN_ERROR) Serial.println("Falha no Inicio");
else if (error == OTA_CONNECT_ERROR) Serial.println("Falha na Conexao");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Falha na Recepcao");
else if (error == OTA_END_ERROR) Serial.println("Falha no Fim");
});
ArduinoOTA.begin();
Serial.println("Pronto");
Serial.print("Endereco IP: ");
Serial.println(WiFi.localIP());
}
void loop() {
ArduinoOTA.handle();
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}