Skip to content

Commit 6fc15a2

Browse files
committed
Merge remote-tracking branch 'remotes/krzychb/master' into docu
2 parents 5192ddb + 08f5e55 commit 6fc15a2

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed

doc/ota_updates/ota_updates.md

+63-15
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,52 @@ title: OTA Update
1010

1111
## Introduction
1212

13-
OTA (Over the Air) update is the process of loading the firmware to ESP module using WiFi connection rather that a serial port. Such functionality became extremely useful in case of limited or no physical access to the module. There is no imposed protection on OTA update process. Such protection should be implemented by developer to ensure that updates are allowed only from legitimate / trusted source.
13+
OTA (Over the Air) update is the process of loading the firmware to ESP module using WiFi connection rather that a serial port. Such functionality became extremely useful in case of limited or no physical access to the module.
1414

1515
OTA may be done from:
1616
- [Arduino IDE](#arduino-ide)
1717
- [HTTP server](#http-server)
1818

1919
In any case first firmware upload have to be done over a serial port. If OTA routines are correctly implemented in sketch, then all subsequent uploads may be done over the air.
2020

21-
The following chapters provide more details and both methods of doing OTA.
21+
There is no imposed security on OTA process from being hacked. It is up to developer to ensure that updates are allowed only from legitimate / trusted source. Once update is complete module restarts and new code is executed. Developer should ensure that application running on module is shut down and restarted in safe manner. Chapters below provide additinal information regarding security and safety of OTA process.
22+
23+
### Security
24+
25+
Module has to be exposed wirelessly to get it updated with a new code. That poses chances of module being violently hacked and loaded with some other firmware. To reduce likelihood of being hacked consider protecting your uploads with a password, selecting certain OTA port, etc.
26+
27+
Check functionality provided with [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library that may improve security:
28+
```cpp
29+
void setPort(uint16_t port);
30+
void setHostname(const char *hostname);
31+
void setPassword(const char *password);
32+
```
33+
If possible implement other means of protection from being hacked, e.g. exposing module for uploads only according to specific schedule, trigger OTA only be user pressing dedicated “Update” button, etc.
34+
35+
### Safety
36+
37+
OTA process takes ESP’s resources and bandwidth during upload. Then module is restarted and a new sketch executed. Analyse and test how it affects functionality of your existing and new sketch.
38+
39+
If ESP is placed in remote location and controlling some equipment, you should put additional attention what happens if operation of this equipment is suddenly interrupted by update process. Therefore decide how to put this equipment into safe state before starting the update. For instance your module may be controlling a garden watering system in a sequence. If this sequence is not properly shut down and a water valve left open, your garden may be flooded if this valve is not closed after OTA is finished and module restarts.
40+
41+
The following functions are provided with [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library and intended to handle functionality of your application during specific stages of OTA on or on an OTA error:
42+
```cpp
43+
void onStart(OTA_CALLBACK(fn));
44+
void onEnd(OTA_CALLBACK(fn));
45+
void onProgress(OTA_CALLBACK_PROGRESS(fn));
46+
void onError(OTA_CALLBACK_ERROR (fn));
47+
```
48+
49+
The following chapters provide more details and specific methods of doing OTA.
2250

2351

2452
## Basic Requirements
2553

2654
- Flash chip size is 2x the size of the sketch.
2755

56+
Two separate, same size memory locations are used alternately. While existing sketch is executed from one location, the new sketch is saved to the other. After reset the new sketch is executed directly from where saved. Location of old sketch will be used for next OTA upload.
57+
58+
2859
## Arduino IDE
2960

3061
Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:
@@ -37,52 +68,69 @@ Uploading modules wirelessly from Arduino IDE is intended for the following typi
3768

3869
#### Let's Do It
3970

40-
OTA process will be demonstrated using:
41-
- DNS_SD_Arduino_OTA.ino sketch available from Arduino IDE
42-
- NodeMCU 1.0 board with ESP-12E module
71+
Currently there are two software configurations that support OTA updates
72+
- [Classic OTA](#classic-ota-configuration): Arduino IDE 1.6.5 and [stable](https://github.com/esp8266/Arduino#staging-version-) (July 23, 2015) or [staging](https://github.com/esp8266/Arduino#staging-version-) (Sep 30, 2015) platform package that provides first OTA implementation, yet without support for [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library. This particular configuration is intended for less experienced users. It soon will be depreciated once implementation below is fully released.
73+
- [ArduinoOTA](#arduinoota-configuration): Arduino-PR-4107-BUILD-421 and latest git version of platform package that includes [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA) library. This configuration features preliminary build of Arduino IDE and is intended for more experienced users. Please mid your step.
74+
75+
Instructions below demonstrate how to configure both [Classic OTA](#classic-ota-configuration) and [ArduinoOTA](#arduinoota-configuration) using NodeMCU 1.0 board with ESP-12E.
76+
77+
##### Classic OTA Configuration
4378

4479
1. Before you begin, please make sure that you have the following installed:
4580
- Arduino IDE and ESP8266 board support as described under https://github.com/esp8266/Arduino#installing-with-boards-manager
46-
- Python 2.7.10 (do not install Python 3.5.0 that is not supported):
47-
1. Upload Python from https://www.python.org/
48-
2. Start installer
49-
3. Select “Add python.exe to Path” (see below – that option is not selected by default)
50-
4. Complete remaining steps of installation
51-
81+
- [Python](https://www.python.org/) 2.7.10 (do not install Python 3.5.0 that is not supported):
82+
83+
**Note:** Windows users should select “Add python.exe to Path” (see below – this option is not selected by default)
84+
5285
![Python installation set up](ota-ide-python-configuration.png)
5386

5487
2. Now prepare the sketch and configuration for the upload over a serial port.
5588

5689
- Start Arduino IDE and load sketch DNS_SD_Arduino_OTA.ino available under File > Examples > ESP8266mDNS
5790

58-
![OTA sketch selection](ota-ide-sketch-selection.png)
91+
![OTA sketch selection](ota-ide-sketch-selection.png)
92+
93+
**Note:** This sketch is available only for stable (July 23, 2015) and staging (Sep 30, 2015) releases installed in Arduino IDE using https://github.com/esp8266/Arduino#installing-with-boards-manager. It was removed in [#980](https://github.com/esp8266/Arduino/pull/980) from Github repository.
5994

6095
- Update ssid and pass in the sketch so the module can join your WiFi network
6196

62-
![ssid and pass entry](ota-ide-ssid-pass-entry.png)
97+
![ssid and pass entry](ota-ide-ssid-pass-entry.png)
6398

6499
- Configure upload parameters as below (you may need to adjust configuration if you are using a different module):
65100

66-
![configuration of serial upload](ota-ide-serial-upload-configuration.png)
101+
![configuration of serial upload](ota-ide-serial-upload-configuration.png)
67102

68103
3. Upload the sketch (Ctrl+U). Once done open Serial Monitor (Ctrl+Shift+M) and check if the module has joined your WiFi network.
69104

70105
![check if module joined network](ota-ide-module-joined-wifi.png)
71106

72-
4. Only if module is connected, after a dozen (or two dozens) of seconds the esp8266-ota port will show up in Arduino IDE:
107+
4. Only if module is connected to network, after a couple of seconds, the esp8266-ota port will show up in Arduino IDE:
73108

74109
![selection og OTA port](ota-ide-ota-port-selection.png)
75110

76111
5. Now get ready for your first OTA upload by changing configuration settings as follows:
77112

78113
![configuration of OTA upload](ota-ide-ota-upload-configuration.png)
79114

115+
**Note:** If you do not see “Upload Using: OTA” option available for “NodeMCU 1.0 (ESP-12E Module)” board, please upload the latest [boards.txt](https://github.com/esp8266/Arduino/blob/master/boards.txt) file from Github repository, replace existing file and restart Arduino IDE.
116+
80117
6. If you have successfully completed all the above steps, you can upload (Ctrl+U) the same (or any other) sketch over OTA:
81118

82119
![OTA upload complete](ota-ide-ota-upload-complete.png)
83120

84121
**Note** To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use DNS_SD_Arduino_OTA.ino as an example.
85122

123+
##### ArduinoOTA Configuration
124+
125+
1. Get the following software:
126+
- Arduino-PR-4107-BUILD-421 - https://github.com/esp8266/Arduino/pull/984#issuecomment-155905800
127+
- Latest git version of pacakge - https://github.com/esp8266/Arduino#using-git-version-
128+
- Python 2.7.10
129+
130+
2. Proceed to step 2 under [Classic OTA Configuration](#classic-ota-configuration) using BasicOTA.ino or OTALeds.ino skech instead.
131+
132+
3. Carry on with remaining steps.
133+
86134

87135
## HTTP Server
88136

0 commit comments

Comments
 (0)