Skip to content

Commit 292cf28

Browse files
committed
Merge branch 'master' into pr_issue_1555
2 parents ebc2667 + 8a26750 commit 292cf28

13 files changed

+165
-47
lines changed

boards.txt

+54-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ thing.name=SparkFun ESP8266 Thing
554554

555555
thing.upload.tool=esptool
556556
thing.upload.speed=921600
557-
thing.upload.resetmethod=nodemcu
557+
thing.upload.resetmethod=ck
558558
thing.upload.maximum_size=434160
559559
thing.upload.maximum_data_size=81920
560560
thing.upload.wait_for_upload_port=true
@@ -606,6 +606,59 @@ thing.menu.UploadSpeed.512000.upload.speed=512000
606606
thing.menu.UploadSpeed.921600=921600
607607
thing.menu.UploadSpeed.921600.upload.speed=921600
608608

609+
##############################################################
610+
thingdev.name=SparkFun ESP8266 Thing Dev
611+
612+
thingdev.upload.tool=esptool
613+
thingdev.upload.speed=921600
614+
thingdev.upload.resetmethod=nodemcu
615+
thingdev.upload.maximum_size=434160
616+
thingdev.upload.maximum_data_size=81920
617+
thingdev.upload.wait_for_upload_port=true
618+
thingdev.serial.disableDTR=true
619+
thingdev.serial.disableRTS=true
620+
621+
thingdev.build.mcu=esp8266
622+
thingdev.build.f_cpu=80000000L
623+
thingdev.build.board=ESP8266_THING_DEV
624+
thingdev.build.core=esp8266
625+
thingdev.build.variant=thing
626+
thingdev.build.flash_mode=dio
627+
# flash chip: AT25SF041 (512 kbyte, 4Mbit)
628+
thingdev.build.flash_size=512K
629+
thingdev.build.flash_ld=eagle.flash.512k64.ld
630+
thingdev.build.flash_freq=40
631+
thingdev.build.debug_port=
632+
thingdev.build.debug_level=
633+
634+
thingdev.menu.CpuFrequency.80=80 MHz
635+
thingdev.menu.CpuFrequency.80.build.f_cpu=80000000L
636+
thingdev.menu.CpuFrequency.160=160 MHz
637+
thingdev.menu.CpuFrequency.160.build.f_cpu=160000000L
638+
639+
thingdev.menu.UploadTool.esptool=Serial
640+
thingdev.menu.UploadTool.esptool.upload.tool=esptool
641+
thingdev.menu.UploadTool.esptool.upload.verbose=-vv
642+
643+
thingdev.menu.UploadSpeed.115200=115200
644+
thingdev.menu.UploadSpeed.115200.upload.speed=115200
645+
thingdev.menu.UploadSpeed.9600=9600
646+
thingdev.menu.UploadSpeed.9600.upload.speed=9600
647+
thingdev.menu.UploadSpeed.57600=57600
648+
thingdev.menu.UploadSpeed.57600.upload.speed=57600
649+
thingdev.menu.UploadSpeed.256000.windows=256000
650+
thingdev.menu.UploadSpeed.256000.upload.speed=256000
651+
thingdev.menu.UploadSpeed.230400.linux=230400
652+
thingdev.menu.UploadSpeed.230400.macosx=230400
653+
thingdev.menu.UploadSpeed.230400.upload.speed=230400
654+
thingdev.menu.UploadSpeed.460800.linux=460800
655+
thingdev.menu.UploadSpeed.460800.macosx=460800
656+
thingdev.menu.UploadSpeed.460800.upload.speed=460800
657+
thingdev.menu.UploadSpeed.512000.windows=512000
658+
thingdev.menu.UploadSpeed.512000.upload.speed=512000
659+
thingdev.menu.UploadSpeed.921600=921600
660+
thingdev.menu.UploadSpeed.921600.upload.speed=921600
661+
609662
##############################################################
610663
esp210.name=SweetPea ESP-210
611664

cores/esp8266/MD5Builder.cpp

+32-33
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,42 @@ void MD5Builder::addHexString(const char * data){
2424
}
2525

2626
bool MD5Builder::addStream(Stream & stream, const size_t total_len) {
27-
const int buf_size = 512;
28-
int bytesleft = total_len;
29-
uint8_t * buf = (uint8_t*) malloc(buf_size);
30-
if(buf) {
31-
while((stream.available() > -1) && (bytesleft > 0)) {
27+
const int buf_size = 512;
28+
int bytesleft = total_len;
29+
uint8_t * buf = (uint8_t*) malloc(buf_size);
30+
if(buf) {
31+
while((stream.available() > -1) && (bytesleft > 0)) {
32+
// get available data size
33+
int sizeAvailable = stream.available();
34+
if(sizeAvailable) {
35+
int readBytes = sizeAvailable;
3236

33-
// get available data size
34-
int sizeAvailable = stream.available();
35-
if(sizeAvailable) {
36-
int readBytes = sizeAvailable;
37-
38-
// read only the asked bytes
39-
if(readBytes > bytesleft) {
40-
readBytes = bytesleft ;
41-
}
37+
// read only the asked bytes
38+
if(readBytes > bytesleft) {
39+
readBytes = bytesleft ;
40+
}
4241

43-
// not read more the buffer can handle
44-
if(readBytes > buf_size) {
45-
readBytes = buf_size;
46-
}
42+
// not read more the buffer can handle
43+
if(readBytes > buf_size) {
44+
readBytes = buf_size;
45+
}
4746

48-
// read data
49-
int bytesread = stream.readBytes(buf, readBytes);
50-
bytesleft -= bytesread;
51-
if(bytesread > 0) {
52-
MD5Update(&_ctx, buf, bytesread);
53-
}
54-
}
55-
// time for network streams
56-
delay(0);
47+
// read data
48+
int bytesread = stream.readBytes(buf, readBytes);
49+
bytesleft -= bytesread;
50+
if(bytesread > 0) {
51+
MD5Update(&_ctx, buf, bytesread);
5752
}
58-
// not free null ptr
59-
free(buf);
60-
return (bytesleft == 0);
61-
} else {
62-
return false;
53+
}
54+
// time for network streams
55+
delay(0);
6356
}
57+
// guaranteed not null
58+
free(buf);
59+
return (bytesleft == 0);
60+
} else {
61+
return false;
62+
}
6463
}
6564

6665
void MD5Builder::calculate(void){
@@ -77,7 +76,7 @@ void MD5Builder::getChars(char * output){
7776
}
7877

7978
String MD5Builder::toString(void){
80-
char out[32];
79+
char out[33];
8180
getChars(out);
8281
return String(out);
8382
}

cores/esp8266/WMath.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@
2626
extern "C" {
2727
#include <stdlib.h>
2828
}
29+
#include "esp8266_peri.h"
2930

3031
void randomSeed(unsigned long seed) {
3132
if(seed != 0) {
32-
srand(seed);
33+
srand((seed ^ RANDOM_REG32));
3334
}
3435
}
3536

3637
long random(long howbig) {
3738
if(howbig == 0) {
3839
return 0;
3940
}
40-
return rand() % howbig;
41+
return (rand() ^ RANDOM_REG32) % howbig;
4142
}
4243

4344
long random(long howsmall, long howbig) {

doc/boards.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ title: Supported Hardware
99
* [NodeMCU 1\.0](#nodemcu-10)
1010
* [Olimex MOD\-WIFI\-ESP8266\-DEV](#olimex-mod-wifi-esp8266-dev)
1111
* [Olimex MOD\-WIFI\-ESP8266](#olimex-mod-wifi-esp8266)
12+
* [Olimex ESP8266\-EVB](#olimex-esp8266-evb)
1213
* [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing)
1314
* [SweetPea ESP\-210](#sweetpea-esp-210)
1415
* [ESPino](#espino)
@@ -77,12 +78,28 @@ Since jumper IO0JP is tied to GPIO0, which is PIN 21, you'll have to ground it b
7778

7879
UART pins for programming and serial I/O are GPIO1 (TXD, pin 3) and GPIO3 (RXD, pin 4).
7980

80-
Get the board schematics [here](https://github.com/OLIMEX/ESP8266/blob/master/HARDWARE/MOD-WIFI-ESP8266-DEV/MOD-WIFI-ESP8266-DEV_schematic.pdf)
81+
You can find the board schematics [here](https://github.com/OLIMEX/ESP8266/blob/master/HARDWARE/MOD-WIFI-ESP8266-DEV/MOD-WIFI-ESP8266-DEV_schematic.pdf)
8182

8283
## Olimex MOD-WIFI-ESP8266
8384

8485
This is a stripped down version of the above. Behaves identically in terms of jumpers but has less pins readily available for I/O. Still 2 MB of SPI flash.
8586

87+
## Olimex ESP8266-EVB
88+
89+
It's a Olimex MOD-WIFI-ESP8266-DEV module installed on the headers of a development board which features some breakout connectors, a button (GPIO0) and a relay (GPIO5).
90+
91+
Programming is pretty straightforward: the board is supported in the Arduino IDE after [installing it via the Board Manager](https://github.com/esp8266/Arduino#installing-with-boards-manager). To download a program you just have to connect GND/RX/TX from a serial/USB adapter to the UEXT connector and press the only button before applying power to enter UART mode.
92+
93+
Don't connect 5V from the serial/USB adapter to the board or you won't be able to power cycle it for UART mode.
94+
95+
You can find the board schematics [here](https://github.com/OLIMEX/ESP8266/blob/master/HARDWARE/ESP8266-EVB/ESP8266-EVB_Rev_A.pdf).
96+
97+
[This guide](https://www.olimex.com/Products/IoT/ESP8266-EVB/resources/ESP8266-EVB-how-to-use-Arduino.pdf) is also useful for the first setup, since it contains the UEXT connector pinout.
98+
99+
Board variants include:
100+
* ESP8266-EVB-BAT: comes with built-in LiPo charger and step-up converter
101+
* ESP8266-EVB-BAT-BOX: as above, but enclosd in a plastic box (non-weatherproof)
102+
86103
## SparkFun ESP8266 Thing ###
87104

88105
Product page: https://www.sparkfun.com/products/13231

doc/libraries.md

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Libraries that don't rely on low-level access to AVR registers should work well.
142142
- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)).
143143
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
144144
- [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library) - Arduino library for the DHT11/DHT22 temperature and humidity sensors. Download latest v1.1.1 library and no changes are necessary. Older versions should initialize DHT as follows: `DHT dht(DHTPIN, DHTTYPE, 15)`
145+
- [Encoder](https://github.com/PaulStoffregen/Encoder) - Arduino library for rotary encoders. Version 1.4 supports ESP8266.
145146
- [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel library, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager).
146147
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with ESP8266. Use the "DmaDriven" or "UartDriven" branches for ESP8266. Includes HSL color support and more.
147148
- [PubSubClient](https://github.com/Imroy/pubsubclient) - MQTT library by @Imroy.
Loading
Loading
Loading
95.7 KB
Loading

doc/ota_updates/ota_updates.md

+35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ title: OTA Update
1212
* [Application Example](#application-example)
1313
* [Classic OTA](#classic-ota)
1414
* [ArduinoOTA](#arduinoota)
15+
* [Password Protection](#password-protection)
1516
* [Troubleshooting](#troubleshooting)
1617
* [Web Browser](#web-browser)
1718
* [Requirements](#requirements-1)
@@ -228,6 +229,40 @@ IP address: 192.168.1.100
228229
**Note:** To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use BasicOTA.ino as an example.
229230

230231

232+
#### Password Protection
233+
234+
Protecting your OTA uploads with password is really straightforward. All you need to do, is to include the following statement in your code:
235+
236+
```cpp
237+
ArduinoOTA.setPassword((const char *)"123");
238+
239+
```
240+
241+
Where ``` 123 ``` is a sample password that you should replace with your own.
242+
243+
Before implementing it in your sketch, it is a good idea to check how it works using *BasicOTA.ino* sketch available under *File > Examples > ArduinoOTA*. Go ahead, open *BasicOTA.ino*, uncomment the above statement that is already there, and upload the sketch. To make troubleshooting easier, do not modify example sketch besides what is absolutely required. This is including original simple ``` 123 ``` OTA password. Then attempt to upload sketch again (using OTA). After compilation is complete, once upload is about to begin, you should see prompt for password as follows:
244+
245+
![Password prompt for OTA upload](a-ota-upload-password-prompt.png)
246+
247+
Enter the password and upload should be initiated as usual with the only difference being ``` Authenticating...OK ``` message visible in upload log.
248+
249+
![ Authenticating...OK during OTA upload](a-ota-upload-password-authenticating-ok.png)
250+
251+
You will not be prompted for a reentering the same password next time. Arduino IDE will remember it for you. You will see prompt for password only after reopening IDE, or if you change it in your sketch, upload the sketch and then try to upload it again.
252+
253+
Please note, it is possible to reveal password entered previously in Arduino IDE, if IDE has not been closed since last upload. This can be done by enabling *Show verbose output during: upload* in *File > Preferences* and attempting to upload the module.
254+
255+
![Verbose upload output with password passing in plan text](a-ota-upload-password-passing-upload-ok.png)
256+
257+
The picture above shows that the password is visible in log as it is passed to *espota.py* upload script.
258+
259+
Another example below shows situation when password is changed between uploads.
260+
261+
![Verbose output when OTA password has been changed between uploads](a-ota-upload-password-passing-again-upload-ok.png)
262+
263+
When uploading, Arduino IDE used previously entered password, so the upload failed and that has been clearly reported by IDE. Only then IDE prompted for a new password. That was entered correctly and second attempt to upload has been successful.
264+
265+
231266
#### Troubleshooting
232267

233268
If OTA update fails, first step is to check for error messages that may be shown in upload window of Arduino IDE. If this is not providing any useful hints try to upload again while checking what is shown by ESP on serial port. Serial Monitor from IDE will not be useful in that case. When attempting to open it, you will likely see the following:

doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ESP8266 has a single ADC channel available to users. It may be used either to re
3636

3737
To read external voltage applied to ADC pin, use `analogRead(A0)`. Input voltage range is 0 — 1.0V.
3838

39-
To read VCC voltage, ADC pin must be kept unconnected. Additionally, the following line has to be added to the sketch:
39+
To read VCC voltage, use `ESP.getVcc()` and ADC pin must be kept unconnected. Additionally, the following line has to be added to the sketch:
4040

4141
```c++
4242
ADC_MODE(ADC_VCC);

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+20-9
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void HTTPClient::setAuthorization(const char * auth) {
264264

265265
/**
266266
* set the timeout for the TCP connection
267-
* @param timeout unsigned int
267+
* @param timeout unsigned int
268268
*/
269269
void HTTPClient::setTimeout(uint16_t timeout) {
270270
_tcpTimeout = timeout;
@@ -273,14 +273,12 @@ void HTTPClient::setTimeout(uint16_t timeout) {
273273
}
274274
}
275275

276-
277-
278276
/**
279277
* use HTTP1.0
280278
* @param timeout
281279
*/
282280
void HTTPClient::useHTTP10(bool useHTTP10) {
283-
_useHTTP10 = useHTTP10;
281+
_useHTTP10 = useHTTP10;
284282
}
285283

286284
/**
@@ -305,6 +303,16 @@ int HTTPClient::POST(String payload) {
305303
return POST((uint8_t *) payload.c_str(), payload.length());
306304
}
307305

306+
/**
307+
* sendRequest
308+
* @param type const char * "GET", "POST", ....
309+
* @param payload String data for the message body
310+
* @return
311+
*/
312+
int HTTPClient::sendRequest(const char * type, String payload) {
313+
return sendRequest(type, (uint8_t *) payload.c_str(), payload.length());
314+
}
315+
308316
/**
309317
* sendRequest
310318
* @param type const char * "GET", "POST", ....
@@ -382,7 +390,6 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
382390
// create buffer for read
383391
uint8_t * buff = (uint8_t *) malloc(buff_size);
384392

385-
386393
if(buff) {
387394
// read all data from stream and send it to server
388395
while(connected() && (stream->available() > -1) && (len > 0 || len == -1)) {
@@ -461,8 +468,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
461468
free(buff);
462469

463470
if(size && (int) size != bytesWritten) {
464-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, size);
465-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
471+
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, size); DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
466472
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
467473
} else {
468474
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload written: %d\n", bytesWritten);
@@ -819,17 +825,21 @@ int HTTPClient::handleHeaderResponse() {
819825
if(!connected()) {
820826
return HTTPC_ERROR_NOT_CONNECTED;
821827
}
828+
822829
String transferEncoding;
823830
_returnCode = -1;
824831
_size = -1;
825832
_transferEncoding = HTTPC_TE_IDENTITY;
833+
unsigned long lastDataTime = millis();
826834

827835
while(connected()) {
828836
size_t len = _tcp->available();
829837
if(len > 0) {
830838
String headerLine = _tcp->readStringUntil('\n');
831839
headerLine.trim(); // remove \r
832840

841+
lastDataTime = millis();
842+
833843
DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] RX: '%s'\n", headerLine.c_str());
834844

835845
if(headerLine.startsWith("HTTP/1.")) {
@@ -885,15 +895,16 @@ int HTTPClient::handleHeaderResponse() {
885895
}
886896

887897
} else {
898+
if((millis() - lastDataTime) > _tcpTimeout) {
899+
return HTTPC_ERROR_READ_TIMEOUT;
900+
}
888901
delay(0);
889902
}
890903
}
891904

892905
return HTTPC_ERROR_CONNECTION_LOST;
893906
}
894907

895-
896-
897908
/**
898909
* write one Data Block to Stream
899910
* @param stream Stream *

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class HTTPClient {
147147
int GET();
148148
int POST(uint8_t * payload, size_t size);
149149
int POST(String payload);
150+
int sendRequest(const char * type, String payload);
150151
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
151152
int sendRequest(const char * type, Stream * stream, size_t size = 0);
152153

0 commit comments

Comments
 (0)