Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Description of the program:

This program sets up WiFi connectivity, OTA (Over-the-Air) uploading capability, and blinks an LED every
one second.

Includes and Variables

It starts by including the necessary libraries:

 ESP8266WiFi - Enables WiFi functionality

 ESP8266mDNS - Enables DNS hostname resolution

 WiFiUdp - Allows UDP communication over WiFi

 ArduinoOTA - Allows updating code wirelessly

It then defines variables:

 ssid - Stores the WiFi network name

 password - Stores the WiFi password

 ledPin - Stores the pin number for the LED

Setup

In the setup() function, it first initializes serial communication and then connects to the WiFi network
using the SSID and password variables.

It waits in a loop for the connection to establish before continuing by checking


WiFi.waitForConnectResult().

Once WiFi is connected, it sets up Over-the-Air uploading:

 Sets a hostname

 Sets an OTA password

 Starts the ArduinoOTA service

Finally, it sets the LED pin as a digital OUTPUT.

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:

 Include ArduinoOTA library

 Initialize WiFi connectivity

 Call ArduinoOTA.begin() to start OTA service

2. Connecting:

 It creates a server on the Arduino IP address, default port 3232

 Checks for a TCP connection request from the IDE

3. Authentication:

 If a password is set with ArduinoOTA.setPassword(), it requests password

 Checks MD5 hash of password before continuing

4. Uploading:

 It communicates over the TCP connection

 The IDE sends the new firmware binary in packets

 The data packets are processed and written to flash memory

5. Rebooting:

 After the full firmware is uploaded, the IDE tells the Arduino to reboot

 This restarts the board and runs the new firmware

6. Handling:

 The loop() continuously checks ArduinoOTA.handle() for any pending actions

 If connection present -> goes through above steps

 If no action -> loop continues remaining program

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.

You might also like