Skip to content

Commit 9e78b6d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ota_commands_in_flash
2 parents e67ebc5 + 916eb89 commit 9e78b6d

File tree

20 files changed

+149
-54
lines changed

20 files changed

+149
-54
lines changed

cores/esp8266/core_esp8266_features.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232

3333
#define WIFI_HAS_EVENT_CALLBACK
3434

35-
#ifdef __cplusplus
36-
3735
#include <stdlib.h> // malloc()
3836
#include <stddef.h> // size_t
37+
#include <stdint.h>
38+
39+
#ifdef __cplusplus
3940

4041
namespace arduino
4142
{

cores/esp8266/core_esp8266_main.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ static void esp_yield_within_cont() {
100100
run_scheduled_recurrent_functions();
101101
}
102102

103-
extern "C" void esp_yield() {
103+
extern "C" void __esp_yield() {
104104
if (can_yield()) {
105105
esp_yield_within_cont();
106106
}
107107
}
108108

109-
extern "C" void esp_schedule() {
110-
// always on CONT stack here
109+
extern "C" void esp_yield() __attribute__ ((weak, alias("__esp_yield")));
110+
111+
extern "C" IRAM_ATTR void esp_schedule() {
111112
ets_post(LOOP_TASK_PRIORITY, 0, 0);
112113
}
113114

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ bool HTTPClient::setURL(const String& url)
551551
}
552552
// disconnect but preserve _client
553553
disconnect(true);
554-
clear();
555554
return beginInternal(url, nullptr);
556555
}
557556

libraries/ESP8266SSDP/ESP8266SSDP.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const char _ssdp_packet_template[] PROGMEM =
7373
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
7474
"USN: %s\r\n" // _uuid
7575
"%s: %s\r\n" // "NT" or "ST", _deviceType
76-
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
76+
"LOCATION: http://%s:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
7777
"\r\n";
7878

7979
static const char _ssdp_schema_template[] PROGMEM =
@@ -88,7 +88,7 @@ static const char _ssdp_schema_template[] PROGMEM =
8888
"<major>1</major>"
8989
"<minor>0</minor>"
9090
"</specVersion>"
91-
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
91+
"<URLBase>http://%s:%u/</URLBase>" // WiFi.localIP(), _port
9292
"<device>"
9393
"<deviceType>%s</deviceType>"
9494
"<friendlyName>%s</friendlyName>"
@@ -247,7 +247,7 @@ void SSDPClass::_send(ssdp_method_t method) {
247247
_uuid,
248248
(method == NONE) ? "ST" : "NT",
249249
(_st_is_uuid) ? _uuid : _deviceType,
250-
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
250+
ip.toString().c_str(), _port, _schemaURL
251251
);
252252

253253
_server->append(buffer, len);
@@ -276,12 +276,12 @@ void SSDPClass::_send(ssdp_method_t method) {
276276
_server->send(remoteAddr, remotePort);
277277
}
278278

279-
void SSDPClass::schema(WiFiClient client) {
279+
void SSDPClass::schema(Print &client) const {
280280
IPAddress ip = WiFi.localIP();
281281
char buffer[strlen_P(_ssdp_schema_template) + 1];
282282
strcpy_P(buffer, _ssdp_schema_template);
283283
client.printf(buffer,
284-
ip[0], ip[1], ip[2], ip[3], _port,
284+
ip.toString().c_str(), _port,
285285
_deviceType,
286286
_friendlyName,
287287
_presentationURL,

libraries/ESP8266SSDP/ESP8266SSDP.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class SSDPClass{
6262
~SSDPClass();
6363
bool begin();
6464
void end();
65-
void schema(WiFiClient client);
65+
void schema(WiFiClient client) const { schema((Print&)std::ref(client)); }
66+
void schema(Print &print) const;
6667
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
6768
void setDeviceType(const char *deviceType);
6869

libraries/ESP8266SdFat

libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ void setup(void) {
6767
server.send(200, "text/plain", "this works as well");
6868
});
6969

70+
server.on("/gif", []() {
71+
static const uint8_t gif[] PROGMEM = {
72+
0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01,
73+
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00,
74+
0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d,
75+
0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c,
76+
0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b
77+
};
78+
char gif_colored[sizeof(gif)];
79+
memcpy_P(gif_colored, gif, sizeof(gif));
80+
// Set the background to a random set of colors
81+
gif_colored[16] = millis() % 256;
82+
gif_colored[17] = millis() % 256;
83+
gif_colored[18] = millis() % 256;
84+
server.send(200, "image/gif", gif_colored, sizeof(gif_colored));
85+
});
86+
7087
server.onNotFound(handleNotFound);
7188

7289
server.begin();

libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino

+1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ void printDirectory() {
241241
entry.close();
242242
}
243243
server.sendContent("]");
244+
server.sendContent(""); // Terminate the HTTP chunked transmission with a 0-length chunk
244245
dir.close();
245246
}
246247

libraries/ESP8266WebServer/src/ESP8266WebServer.h

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ class ESP8266WebServerTemplate
127127
void send(int code, const char* content_type = NULL, const String& content = String(""));
128128
void send(int code, char* content_type, const String& content);
129129
void send(int code, const String& content_type, const String& content);
130+
void send(int code, const char *content_type, const char *content, size_t content_length = 0) {
131+
if (content_length == 0) {
132+
content_length = strlen_P(content);
133+
}
134+
send_P(code, content_type, content, content_length);
135+
}
136+
void send(int code, const char *content_type, const uint8_t *content, size_t content_length) {
137+
send_P(code, content_type, (const char *)content, content_length);
138+
}
130139
void send_P(int code, PGM_P content_type, PGM_P content);
131140
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);
132141

libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
102102
// Append whatever follows this URI in request to get the file path.
103103
path += requestUri.substring(_baseUriLength);
104104

105-
if (!_fs.exists(path) && path.endsWith(".htm")) {
105+
if (!_fs.exists(path) && path.endsWith(".htm") && _fs.exists(path + "l")) {
106106
path += "l";
107107
}
108108
}

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) {
443443
//tasks to wait correctly.
444444
constexpr unsigned int timeoutValue = 1000; //1 second
445445
if(can_yield()) {
446-
using oneShot = esp8266::polledTimeout::oneShotFastUs;
446+
using oneShot = esp8266::polledTimeout::oneShotFastMs;
447447
oneShot timeout(timeoutValue);
448448
while(wifi_get_opmode() != (uint8) m && !timeout)
449449
delay(5);

libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino

+23
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ void setup() {
4343

4444
}
4545

46+
void update_started() {
47+
USE_SERIAL.println("CALLBACK: HTTP update process started");
48+
}
49+
50+
void update_finished() {
51+
USE_SERIAL.println("CALLBACK: HTTP update process finished");
52+
}
53+
54+
void update_progress(int cur, int total) {
55+
USE_SERIAL.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
56+
}
57+
58+
void update_error(int err) {
59+
USE_SERIAL.printf("CALLBACK: HTTP update fatal error code %d\n", err);
60+
}
61+
62+
4663
void loop() {
4764
// wait for WiFi connection
4865
if ((WiFiMulti.run() == WL_CONNECTED)) {
@@ -57,6 +74,12 @@ void loop() {
5774
// value is used to put the LED on. If the LED is on with HIGH, that value should be passed
5875
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
5976

77+
// Add optional callback notifiers
78+
ESPhttpUpdate.onStart(update_started);
79+
ESPhttpUpdate.onEnd(update_finished);
80+
ESPhttpUpdate.onProgress(update_progress);
81+
ESPhttpUpdate.onError(update_error);
82+
6083
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "http://server/file.bin");
6184
// Or:
6285
//t_httpUpdate_return ret = ESPhttpUpdate.update(client, "server", 80, "file.bin");

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+34-14
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
294294

295295
if(code <= 0) {
296296
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP error: %s\n", http.errorToString(code).c_str());
297-
_lastError = code;
297+
_setLastError(code);
298298
http.end();
299299
return HTTP_UPDATE_FAILED;
300300
}
@@ -334,10 +334,14 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
334334
}
335335
}
336336

337-
if(!startUpdate) {
338-
_lastError = HTTP_UE_TOO_LESS_SPACE;
337+
if (!startUpdate) {
338+
_setLastError(HTTP_UE_TOO_LESS_SPACE);
339339
ret = HTTP_UPDATE_FAILED;
340340
} else {
341+
// Warn main app we're starting up...
342+
if (_cbStart) {
343+
_cbStart();
344+
}
341345

342346
WiFiClient * tcp = http.getStreamPtr();
343347

@@ -360,15 +364,15 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
360364
uint8_t buf[4];
361365
if(tcp->peekBytes(&buf[0], 4) != 4) {
362366
DEBUG_HTTP_UPDATE("[httpUpdate] peekBytes magic header failed\n");
363-
_lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
367+
_setLastError(HTTP_UE_BIN_VERIFY_HEADER_FAILED);
364368
http.end();
365369
return HTTP_UPDATE_FAILED;
366370
}
367371

368372
// check for valid first magic byte
369373
if(buf[0] != 0xE9) {
370374
DEBUG_HTTP_UPDATE("[httpUpdate] Magic header does not start with 0xE9\n");
371-
_lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
375+
_setLastError(HTTP_UE_BIN_VERIFY_HEADER_FAILED);
372376
http.end();
373377
return HTTP_UPDATE_FAILED;
374378

@@ -379,7 +383,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
379383
// check if new bin fits to SPI flash
380384
if(bin_flash_size > ESP.getFlashChipRealSize()) {
381385
DEBUG_HTTP_UPDATE("[httpUpdate] New binary does not fit SPI Flash size\n");
382-
_lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
386+
_setLastError(HTTP_UE_BIN_FOR_WRONG_FLASH);
383387
http.end();
384388
return HTTP_UPDATE_FAILED;
385389
}
@@ -388,6 +392,10 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
388392
ret = HTTP_UPDATE_OK;
389393
DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
390394
http.end();
395+
// Warn main app we're all done
396+
if (_cbEnd) {
397+
_cbEnd();
398+
}
391399

392400
#ifdef ATOMIC_FS_UPDATE
393401
if(_rebootOnUpdate) {
@@ -403,7 +411,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
403411
}
404412
}
405413
} else {
406-
_lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE;
414+
_setLastError(HTTP_UE_SERVER_NOT_REPORT_SIZE);
407415
ret = HTTP_UPDATE_FAILED;
408416
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length was 0 or wasn't set by Server?!\n");
409417
}
@@ -413,15 +421,15 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
413421
ret = HTTP_UPDATE_NO_UPDATES;
414422
break;
415423
case HTTP_CODE_NOT_FOUND:
416-
_lastError = HTTP_UE_SERVER_FILE_NOT_FOUND;
424+
_setLastError(HTTP_UE_SERVER_FILE_NOT_FOUND);
417425
ret = HTTP_UPDATE_FAILED;
418426
break;
419427
case HTTP_CODE_FORBIDDEN:
420-
_lastError = HTTP_UE_SERVER_FORBIDDEN;
428+
_setLastError(HTTP_UE_SERVER_FORBIDDEN);
421429
ret = HTTP_UPDATE_FAILED;
422430
break;
423431
default:
424-
_lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE;
432+
_setLastError(HTTP_UE_SERVER_WRONG_HTTP_CODE);
425433
ret = HTTP_UPDATE_FAILED;
426434
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP Code is (%d)\n", code);
427435
//http.writeToStream(&Serial1);
@@ -444,32 +452,44 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, const String& md5,
444452

445453
StreamString error;
446454

455+
if (_cbProgress) {
456+
Update.onProgress(_cbProgress);
457+
}
458+
447459
if(!Update.begin(size, command, _ledPin, _ledOn)) {
448-
_lastError = Update.getError();
460+
_setLastError(Update.getError());
449461
Update.printError(error);
450462
error.trim(); // remove line ending
451463
DEBUG_HTTP_UPDATE("[httpUpdate] Update.begin failed! (%s)\n", error.c_str());
452464
return false;
453465
}
454466

467+
if (_cbProgress) {
468+
_cbProgress(0, size);
469+
}
470+
455471
if(md5.length()) {
456472
if(!Update.setMD5(md5.c_str())) {
457-
_lastError = HTTP_UE_SERVER_FAULTY_MD5;
473+
_setLastError(HTTP_UE_SERVER_FAULTY_MD5);
458474
DEBUG_HTTP_UPDATE("[httpUpdate] Update.setMD5 failed! (%s)\n", md5.c_str());
459475
return false;
460476
}
461477
}
462478

463479
if(Update.writeStream(in) != size) {
464-
_lastError = Update.getError();
480+
_setLastError(Update.getError());
465481
Update.printError(error);
466482
error.trim(); // remove line ending
467483
DEBUG_HTTP_UPDATE("[httpUpdate] Update.writeStream failed! (%s)\n", error.c_str());
468484
return false;
469485
}
470486

487+
if (_cbProgress) {
488+
_cbProgress(size, size);
489+
}
490+
471491
if(!Update.end()) {
472-
_lastError = Update.getError();
492+
_setLastError(Update.getError());
473493
Update.printError(error);
474494
error.trim(); // remove line ending
475495
DEBUG_HTTP_UPDATE("[httpUpdate] Update.end failed! (%s)\n", error.c_str());

0 commit comments

Comments
 (0)