Professional Documents
Culture Documents
OTA_uload
OTA_uload
This program sets up WiFi connectivity, OTA (Over-the-Air) uploading capability, and blinks an LED every
one second.
Setup
In the setup() function, it first initializes serial communication and then connects to the WiFi network
using the SSID and password variables.
Sets a hostname
Main Loop
The loop() function first checks for any incoming OTA updates using ArduinoOTA.handle().
It then turns the LED HIGH for 1 second, goes LOW for 1 second - blinking it once every second. This
loops continuously.
Commands list:
Command Description
Includes the ESP8266WiFi library which enables WiFi
#include <ESP8266WiFi.h>
functionality by adding networking capabilities
Includes the ESP8266mDNS library which enables the
#include
DNS service. This allows using hostnames instead of
<ESP8266mDNS.h>
IP addresses when connecting
Includes the WiFiUdp library which enables UDP
#include <WiFiUdp.h>
communication over WiFi
Includes the ArduinoOTA library which allows
#include <ArduinoOTA.h>
uploading code wirelessly over WiFi
Defines the ssid variable which stores the WiFi
const char* ssid
network name as a string
Defines the password variable which stores the WiFi
const char* password
password as a string
Defines ledPin as a constant integer to store the pin
const int ledPin
number connected to the LED
void setup() The setup function runs once at startup
Serial.begin(115200) Initializes serial communication at 115200 baud rate
Starts connecting to the WiFi network using the
WiFi.begin(ssid, password)
defined SSID and password
Waits for the connection result, returns when
WiFi.waitForConnectResult()
connected
ArduinoOTA.setHostname() Sets the hostname for ArduinoOTA
ArduinoOTA.setPassword() Sets a password for uploading via ArduinoOTA
ArduinoOTA.begin() Starts the ArduinoOTA service
pinMode(ledPin, OUTPUT) Sets ledPin as a digital OUTPUT pin
void loop() The main program loop, runs continuously
How OTA works:
Arduino OTA (Over-the-Air) programming allows updating the Arduino firmware wirelessly over WiFi
instead of having to connect it via a USB cable each time. It works as follows:
1. Setup:
2. Connecting:
3. Authentication:
4. Uploading:
5. Rebooting:
After the full firmware is uploaded, the IDE tells the Arduino to reboot
6. Handling:
it allows wireless reprogramming over WiFi by establishing a TCP connection from the IDE which sends
firmware packets. The Arduino handles programming the flash + restart.