|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- # step by step guide
-
- __start with [ArduinoOTA basic example](https://github.com/esp8266/Arduino/blob/master/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino)__
-
- ```cpp
- void setup() {
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.waitForConnectResult() != WL_CONNECTED) {
- delay(5000);
- ESP.restart(); /* reload application */
- }
-
- /* register callbacks for OTA events */
- ArduinoOTA.onStart([]() { /* ... */ });
- ArduinoOTA.onEnd ([]() { /* ... */ });
- ArduinoOTA.onError([](ota_error_t error) { /* ... */ });
-
- /* setup OTA for listening on default UDP-port 8266 */
- ArduinoOTA.begin();
- }
-
- void loop() {
- /* check for incoming OTA update */
- ArduinoOTA.handle();
- }
- ```
- ___
-
- __open serial port to esp8266 and reset__
-
- ```bash
- # example output after reset
- ets Jan 8 2013,rst cause:2, boot mode:(3,7)
-
- # load binary
- load 0x4010f000, len 3460, room 16
- tail 4
- chksum 0xcc
- load 0x3fff20b8, len 40, room 4
- tail 4
- chksum 0xc9
- csum 0xc9
- v00040b70
- ~ld
- ```
- ___
-
- __Boot Messages and Modes, see also [detailed documentation](https://github.com/esp8266/Arduino/blob/master/doc/boards.rst)__
-
- at startup the ESP prints out the current boot mode example:
- ```
- rst cause:2, boot mode:(3,6)
- ```
-
- | rst cause| Description |
- |----------|------------------|
- | 0 | unknown |
- | 1 | normal boot |
- | 2 | reset pin |
- | 3 | software reset |
- | 4 | watchdog reset |
-
- ```
- boot mode:(x,y)
- ```
-
- | x | GPIO15 | GPIO0 | GPIO2 | Mode |
- |----------|----------|---------|---------|-------------|
- | 1 | 0V | 0V | 3.3V | Uart |
- | 3 | 0V | 3.3V | 3.3V | Flash |
-
- __note:__ __y__ represents the position of the boot file
-
- ___
-
- __modify__ _platformio.ini_
-
- ```ini
- ; example platformio.ini
- [env:esp01_1m]
- platform = espressif8266
- board = esp01_1m
- framework = arduino
-
- upload_port = COM6
- monitor_speed = 74880
- ```
-
- ___
-
- __upload compiled binary via uart__
-
- __note__: close serial port
-
- ```bash
- $ pio run -t upload
- # or use upload button in vscode
- ```
-
- __open serial port to esp8266 and check Wi-Fi connection__
-
- ```bash
- # monitor output:
- Ready
- IP address: # your local IP #
- ```
- __modify platformio.ini accordingly__
- ```ini
- ; new platformio.ini for OTA
- [env:esp01_1m]
- platform = espressif8266
- board = esp01_1m
- framework = arduino
-
- upload_protocol = espota
- upload_port = # your local IP #
- monitor_speed = 74880
- ```
- ___
-
- __now you can upload new binaries via OTA__
-
- ```bash
- $ pio run -t upload
- # or use upload button in vscode
- ```
-
- __what`s happening can be observed with [debug_ser.py](debug_ser.py), _PySerial_ needed !__
-
- ```bash
- $ python3 debug_ser.py
-
- # serial output:
- [OTA] Start updating sketch
- [OTA] Progress: 100%
- [OTA] End
-
- ets Jan 8 2013,rst cause:2, boot mode:(3,7)
-
- load 0x4010f000, len 3460, room 16
- tail 4
- chksum 0xcc
- load 0x3fff20b8, len 40, room 4
- tail 4
- chksum 0xc9
- csum 0xc9
- v0004e770
- @cp:B0 # copying new binary into boot flash region
- ld
-
- [Program] Booting
- [Program] OTA and HTTPServer ready !
- [Program] IP address: 192.168.10.108
- ```
-
- ___
-
- __Process of updating__
-
- ![ota flash layout](ota_flash.png)
|