├── img ├── arduino-board-select.png ├── arduino-sketch-edit.png ├── arduino-upload-speed.png ├── arduino-board-flashing.png ├── arduino-board-install.png ├── arduino-sketch-ota-option.png └── arduino-board-manager-link.png ├── ota-basic └── ota-basic.ino └── README.md /img/arduino-board-select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-board-select.png -------------------------------------------------------------------------------- /img/arduino-sketch-edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-sketch-edit.png -------------------------------------------------------------------------------- /img/arduino-upload-speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-upload-speed.png -------------------------------------------------------------------------------- /img/arduino-board-flashing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-board-flashing.png -------------------------------------------------------------------------------- /img/arduino-board-install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-board-install.png -------------------------------------------------------------------------------- /img/arduino-sketch-ota-option.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-sketch-ota-option.png -------------------------------------------------------------------------------- /img/arduino-board-manager-link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esp8266-examples/ota-basic/HEAD/img/arduino-board-manager-link.png -------------------------------------------------------------------------------- /ota-basic/ota-basic.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | const char* ssid = "SSID_NAME"; 7 | const char* password = "PASSWORD"; 8 | 9 | //Blink LED pin 10 | int ledPin = 2; 11 | 12 | //To make Arduino software autodetect OTA device 13 | WiFiServer TelnetServer(8266); 14 | 15 | void setup() { 16 | //To make Arduino software autodetect OTA device 17 | TelnetServer.begin(); 18 | 19 | Serial.begin(115200); 20 | Serial.println("Booting..."); 21 | WiFi.mode(WIFI_STA); 22 | WiFi.begin(ssid, password); 23 | while (WiFi.waitForConnectResult() != WL_CONNECTED) { 24 | Serial.println("Connection Failed! Rebooting..."); 25 | delay(5000); 26 | ESP.restart(); 27 | } 28 | // Port defaults to 8266 29 | //ArduinoOTA.setPort(8266); 30 | // Hostname defaults to esp8266-[ChipID] 31 | //ArduinoOTA.setHostname("myesp8266"); 32 | // No authentication by default 33 | //ArduinoOTA.setPassword((const char *)"xxxxx"); 34 | 35 | ArduinoOTA.onStart([]() { 36 | Serial.println("OTA Start"); 37 | }); 38 | ArduinoOTA.onEnd([]() { 39 | Serial.println("OTA End"); 40 | Serial.println("Rebooting..."); 41 | }); 42 | ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { 43 | Serial.printf("Progress: %u%%\r\n", (progress / (total / 100))); 44 | }); 45 | ArduinoOTA.onError([](ota_error_t error) { 46 | Serial.printf("Error[%u]: ", error); 47 | if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); 48 | else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); 49 | else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); 50 | else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); 51 | else if (error == OTA_END_ERROR) Serial.println("End Failed"); 52 | }); 53 | ArduinoOTA.begin(); 54 | Serial.println("Ready"); 55 | Serial.print("IP address: "); 56 | Serial.println(WiFi.localIP()); 57 | 58 | //set LED pin as output 59 | pinMode(ledPin, OUTPUT); 60 | } 61 | 62 | void loop() { 63 | ArduinoOTA.handle(); 64 | 65 | //Make LED blink 66 | digitalWrite(ledPin, HIGH); 67 | delay(250); 68 | digitalWrite(ledPin, LOW); 69 | delay(250); 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ota-basic 2 | OTA basic example for the esp8266 3 | 4 | The sketch inside 'ota-basic' folder enables Arduino Software to load a new sketch into the ESP8266 over a WIFI connection (without a programmer or a USB-Serial adapter). 5 | 6 | Aditionally, it makes a led blink on pin 2 to check that the ESP8266 is running. 7 | 8 | #Contents 9 | * [Prerequisites and limitations](#prerequisites-and-limitations) 10 | * [Installing software with Boards Manager](#installing-software-with-boards-manager) 11 | * [Flashing the esp8266 for the first time](#flashing-the-esp8266-for-the-first-time) 12 | * [OTA programming](#ota-programming) 13 | * [Issues and support](#issues-and-support) 14 | * [Contributing](#contributing) 15 | * [License and credits](#license-and-credits) 16 | 17 | 18 | 19 | #Prerequisites and limitations: 20 | To use this sketch you need: 21 | - An esp8266 board 22 | - Arduino software 1.6.7 or later [Download here](https://www.arduino.cc/en/Main/Software) 23 | - An esp8266 programmer (only to flash the esp8266 the first time) 24 | 25 | If you edit this sketch, you must consider that, to make OTA work: 26 | - The sketch compiled size cannot be greater than 50% of the esp8266 memory 27 | - If you use File System Wrapper, you maximun sketch size must be: (TotalMemory-FilesystemSize)/2 28 | 29 | #Installing software with Boards Manager 30 | * Install the Arduino Software (1.6.7 version or later) 31 | * Update Board Manager with custom URL:Open up Arduino, then go to the Preferences (**File > Preferences**). Then, towards the bottom of the window, copy this URL into the “Additional Board Manager URLs” text box: 32 | 33 | http://arduino.esp8266.com/stable/package_esp8266com_index.json 34 | 35 |

36 | 37 | Note: You can add multiple URLs, separating them with commas. 38 | 39 | * Open Boards Manager from **Tools > Board** menu and install esp8266 platform (and don't forget to select your ESP8266 board from **Tools > Board** menu after installation). 40 | 41 |

42 |

43 | 44 | #Flashing the esp8266 for the first time 45 | To make the esp8266 OTA ready we need to flash de initial firmware with a esp8266 flashing circuit. For example: 46 | 47 |

48 | 49 | You'll need to edit the sketch to set your WIFI configuration. Change the 'ssid' and 'password' value to match your WIFI settings: 50 |

51 | 52 | And set the configutarion of your programming circuit: 53 | - Board: If you don't know which is yours then select 'Generic ESP8266 module' 54 | - Port: The COM port of your programmer 55 | - Speed: 115200 56 | 57 |

58 | 59 | Now, we can upload the sketch to de esp8266. 60 | 61 | #OTA programming 62 | Once we have flashed the firmware of the esp8266 with an OTA enabled firmware we need to restart Arduino Software and you can dissconect the programmer serial port (or maintain it connected to use serial port for debugging, for example). 63 | Now, in the **Tools > Port** menu we'll find a new option, starting with 'esp8266' and including a local IP address. We must select that serial port. After that, go to **Tools > Upload using** and select **OTA** option. 64 | 65 |

66 | 67 | Just try to upload de sketch and it'll upload over WIFI. **Note that WIFI programming is A LOT faster than serial programming**. 68 | 69 | #Issues and support 70 | 71 | If you encounter an issue, you are welcome to submit it here on Github: [https://github.com/esp8266-examples/ota-basic/issues](https://github.com/esp8266-examples/ota-basic/issues). Please provide as much context as possible: version which you are using (you can check it in Boards Manager), your sketch code, serial output, board model, IDE settings (board selection, flash size, etc). 72 | 73 | #Contributing 74 | 75 | For minor fixes of code and documentation, go ahead and submit a pull request. 76 | 77 | Larger changes (rewriting parts of existing code from scratch, adding new functions to the core, adding new libraries) should generally be discussed in the chat first. 78 | 79 | Feature branches with lots of small commits (especially titled "oops", "fix typo", "forgot to add file", etc.) should be squashed before opening a pull request. At the same time, please refrain from putting multiple unrelated changes into a single pull request. 80 | 81 | #License and credits 82 | 83 | Arduino IDE is developed and maintained by the Arduino team. The IDE is licensed under GPL. 84 | 85 | ESP8266 core includes an xtensa gcc toolchain, which is also under GPL. 86 | 87 | Esptool written by Christian Klippel is licensed under GPLv2, currently maintained by Ivan Grokhotkov: [https://github.com/igrr/esptool-ck](https://github.com/igrr/esptool-ck). 88 | 89 | Espressif SDK included in this build is under Espressif MIT License. 90 | 91 | ESP8266 core files are licensed under LGPL. 92 | 93 | SPI Flash File System (SPIFFS) written by Peter Andersson is used in this project. It is distributed under MIT license. 94 | --------------------------------------------------------------------------------