Saturday, January 22, 2022

0000 0000 1000 0101

ESP8266 OTA programming

For some reason (old age?) I find the idea of programming a device via WiFi quite astonishing. That such a thing exists, that I can do it, and that it works for me in the end seems miraculous!


In the video below I grab an ESP-12S, solder it to a PCB adaptery thingo and program it up with the following OTA code...

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "URWiFiSSID";
const char* password = "URWiFiPWD";
const char* host = "Blinky OTA";

#define led_pin 4

void setup() {

  /* switch on led */
  pinMode(led_pin, OUTPUT);
  digitalWrite(led_pin, LOW);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  }

  ArduinoOTA.setHostname(host);

  ArduinoOTA.onError([](ota_error_t error) {
    (void)error;
    ESP.restart();
  });

  ArduinoOTA.begin();

}

void loop() {
  ArduinoOTA.handle();
  digitalWrite(led_pin,HIGH);
  delay(50);
  digitalWrite(led_pin, LOW);
  delay(1000);
  
}

The whole process worked surprisingly well (with a couple of caveats explained in the video), and now I'd like to try it with an ESP32!




No comments:

Post a Comment