Skip to content

Instantly share code, notes, and snippets.

@igrr
Created June 11, 2015 15:24
Show Gist options
  • Save igrr/43d5c52328e955bb6b09 to your computer and use it in GitHub Desktop.
Save igrr/43d5c52328e955bb6b09 to your computer and use it in GitHub Desktop.
ESP8266 Arduino OTA example v1
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
const char* ssid = "..........";
const char* password = "...........";
WiFiUDP listener;
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println("");
Serial.println("OTA test");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
listener.begin(8266);
Serial.print("Sketch size: ");
Serial.println(ESP.getSketchSize());
Serial.print("Free size: ");
Serial.println(ESP.getFreeSketchSpace());
}
void loop() {
int cb = listener.parsePacket();
if (cb) {
IPAddress remote = listener.remoteIP();
int cmd = listener.parseInt();
int port = listener.parseInt();
int sz = listener.parseInt();
Serial.println("Got packet");
Serial.printf("%d %d %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");
}
}
delay(100);
}
@bkrajendra
Copy link

Where do we need to setup ESP IP in arduino IDE?

@jindrichsirucek
Copy link

Hi I have the same question as bkrajendra.. how to setup adress of esp in IDE.. So far I have modified espota.py directly.. but is annoying to rewrite it for each ESP module.. thx..

@Vikingfr
Copy link

@bkrajendra : in arduino IDE -> Tools > port. Your esp should appear in this section under "network ports". But I doesn't upload for me
(sorry if bad englsih, I'm french)

@starlino
Copy link

starlino commented Nov 7, 2015

To specify IP instead of serial port (in case it does not appear in the list):
File > Prefrences will show your preferences file
C:\Users\AppData\Roaming\Arduino\preferences.txt
Edit with IP of esp module, for example :
serial.port=192.168.0.50
Restart Arduino and check bottom-right corner to see your IP is displayed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment