@@ -3,21 +3,20 @@ title: OTA Update
3
3
---
4
4
5
5
## Table of Contents
6
- * [ Requirements] ( #Requirements )
6
+ * [ Basic Requirements] ( #basic-requirements )
7
7
* [ Arduino IDE] ( #arduino-ide )
8
8
* [ HTTP Server] ( #http-server )
9
9
* [ Stream Interface] ( #stream-interface )
10
10
11
- ## Requirements
11
+ ## Basic Requirements
12
12
13
- Basic requirement:
14
13
- Flash chip size is 2x the size of the sketch
15
14
16
15
## Arduino IDE
17
16
18
17
TODO describe Arduino IDE OTA process
19
18
20
- ### Requirements
19
+ #### Requirements
21
20
- The ESP and the Computer must be connected to the Same network.
22
21
23
22
@@ -27,18 +26,29 @@ the ```ESPhttpUpdate``` class can check for updates and download a binary file f
27
26
It is possible to download updates from every IP or domain address on the Network or Internet.
28
27
29
28
30
- ### Requirements
29
+ #### Requirements
31
30
- web server
32
31
33
32
34
- ### Arduino code
33
+ #### Arduino code
34
+
35
+ ##### simple updater
36
+
37
+ the Simple Updater downloads the File every time the function is called.
35
38
36
- simple updater:
37
39
``` cpp
38
40
ESPhttpUpdate.update(" 192.168.0.2" , 80 , " /arduino.bin" );
39
41
```
40
42
41
- advanced:
43
+ ##### advanced updater
44
+
45
+ Its possible to point to a script at the server.
46
+ If a version String is delivered to the Function this String will be send to the server.
47
+ A Server side Update check is now possible.
48
+
49
+ the Server can return a binary file for update (Header 200)
50
+ or it return header 304 to notify the ESP that no Update is needed.
51
+
42
52
``` cpp
43
53
t_httpUpdate_return ret = ESPhttpUpdate.update(" 192.168.0.2" , 80 , " /esp/update/arduino.php" , " optional current version string here" );
44
54
switch (ret) {
@@ -54,9 +64,93 @@ switch(ret) {
54
64
}
55
65
```
56
66
57
- ### Server request handling
67
+ #### Server request handling
68
+
69
+ ##### simple updater
70
+
71
+ for the simple Updater the Server only needs to deliver the binary file for update.
72
+
73
+ ##### advanced updater
74
+
75
+ for advanced update management a Script needs to run at the Server side, for example a PHP script.
76
+ at every Update request the the ESP sends some informations in the Header to the Server
77
+
78
+ example Header data:
79
+ ```
80
+ [HTTP_USER_AGENT] => ESP8266-http-Update
81
+ [HTTP_X_ESP8266_STA_MAC] => 18:FE:AA:AA:AA:AA
82
+ [HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
83
+ [HTTP_X_ESP8266_FREE_SPACE] => 671744
84
+ [HTTP_X_ESP8266_SKETCH_SIZE] => 373940
85
+ [HTTP_X_ESP8266_CHIP_SIZE] => 524288
86
+ [HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
87
+ [HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
88
+ ```
89
+
90
+ with this information the script now can check if a update is needed.
91
+ It is also possible to deliver different binary´s based on the MAC address for example.
92
+
93
+ script example:
94
+ ``` php
95
+ <?PHP
96
+
97
+ header('Content-type: text/plain; charset=utf8', true);
98
+
99
+ function check_header($name, $value = false) {
100
+ if(!isset($_SERVER[$name])) {
101
+ return false;
102
+ }
103
+ if($value && $_SERVER[$name] != $value) {
104
+ return false;
105
+ }
106
+ return true;
107
+ }
108
+
109
+ function sendFile($path) {
110
+ header($_SERVER["SERVER_PROTOCOL"].' 200 OK', true, 200);
111
+ header('Content-Type: application/octet-stream', true);
112
+ header('Content-Disposition: attachment; filename='.basename($path));
113
+ header('Content-Length: '.filesize($path), true);
114
+ readfile($path);
115
+ }
116
+
117
+ if(!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
118
+ header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
119
+ echo "only for ESP8266 updater!\n";
120
+ exit();
121
+ }
122
+
123
+ if(
124
+ !check_header('HTTP_X_ESP8266_STA_MAC') ||
125
+ !check_header('HTTP_X_ESP8266_AP_MAC') ||
126
+ !check_header('HTTP_X_ESP8266_FREE_SPACE') ||
127
+ !check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
128
+ !check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
129
+ !check_header('HTTP_X_ESP8266_SDK_VERSION') ||
130
+ !check_header('HTTP_X_ESP8266_VERSION')
131
+ ) {
132
+ header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
133
+ echo "only for ESP8266 updater! (header)\n";
134
+ exit();
135
+ }
136
+
137
+ $db = array(
138
+ "18:FE:AA:AA:AA:AA" => "DOOR-7-g14f53a19",
139
+ "18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
140
+ );
141
+
142
+ if(isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
143
+ if($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION']) ) {
144
+ sendFile("./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']]."bin");
145
+ } else {
146
+ header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
147
+ }
148
+ }
149
+
150
+ header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
151
+
152
+ ```
58
153
59
- TODO server side
60
154
61
155
## Stream Interface
62
156
0 commit comments