mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Initial Upload From IDE
For Test ONLY
This commit is contained in:
committed by
Ivan Grokhotkov
parent
a82796f83f
commit
dc9072b94b
@ -0,0 +1,50 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <WiFiUDP.h>
|
||||
|
||||
const char* host = "esp8266-ota";
|
||||
const char* ssid = "**********";
|
||||
const char* pass = "**********";
|
||||
const uint16_t aport = 8266;
|
||||
|
||||
WiFiUDP listener;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
Serial.println("");
|
||||
Serial.println("Arduino OTA Test");
|
||||
|
||||
Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
|
||||
Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
||||
MDNS.begin(host);
|
||||
MDNS.addService("arduino", "tcp", aport);
|
||||
listener.begin(aport);
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (ota_cmd_listener.parsePacket()) {
|
||||
IPAddress remote = listener.remoteIP();
|
||||
int cmd = listener.parseInt();
|
||||
int port = listener.parseInt();
|
||||
int sz = listener.parseInt();
|
||||
Serial.printf("Starting Update: cmd:%d, port:%d, size:%d\r\n", cmd, port, sz);
|
||||
WiFiClient cl;
|
||||
if (!cl.connect(remote, port)) {
|
||||
Serial.println("Failed to connect");
|
||||
return;
|
||||
}
|
||||
listener.stop();
|
||||
if (!ESP.updateSketch(cl, sz)) {
|
||||
Serial.println("Update failed");
|
||||
listener.begin(aport);
|
||||
}
|
||||
}
|
||||
delay(100);
|
||||
}
|
Reference in New Issue
Block a user