diff --git a/boards.txt b/boards.txt index 057216718..6cfdcff06 100644 --- a/boards.txt +++ b/boards.txt @@ -554,7 +554,7 @@ thing.name=SparkFun ESP8266 Thing thing.upload.tool=esptool thing.upload.speed=921600 -thing.upload.resetmethod=nodemcu +thing.upload.resetmethod=ck thing.upload.maximum_size=434160 thing.upload.maximum_data_size=81920 thing.upload.wait_for_upload_port=true @@ -606,6 +606,59 @@ thing.menu.UploadSpeed.512000.upload.speed=512000 thing.menu.UploadSpeed.921600=921600 thing.menu.UploadSpeed.921600.upload.speed=921600 +############################################################## +thingdev.name=SparkFun ESP8266 Thing Dev + +thingdev.upload.tool=esptool +thingdev.upload.speed=921600 +thingdev.upload.resetmethod=nodemcu +thingdev.upload.maximum_size=434160 +thingdev.upload.maximum_data_size=81920 +thingdev.upload.wait_for_upload_port=true +thingdev.serial.disableDTR=true +thingdev.serial.disableRTS=true + +thingdev.build.mcu=esp8266 +thingdev.build.f_cpu=80000000L +thingdev.build.board=ESP8266_THING_DEV +thingdev.build.core=esp8266 +thingdev.build.variant=thing +thingdev.build.flash_mode=dio +# flash chip: AT25SF041 (512 kbyte, 4Mbit) +thingdev.build.flash_size=512K +thingdev.build.flash_ld=eagle.flash.512k64.ld +thingdev.build.flash_freq=40 +thingdev.build.debug_port= +thingdev.build.debug_level= + +thingdev.menu.CpuFrequency.80=80 MHz +thingdev.menu.CpuFrequency.80.build.f_cpu=80000000L +thingdev.menu.CpuFrequency.160=160 MHz +thingdev.menu.CpuFrequency.160.build.f_cpu=160000000L + +thingdev.menu.UploadTool.esptool=Serial +thingdev.menu.UploadTool.esptool.upload.tool=esptool +thingdev.menu.UploadTool.esptool.upload.verbose=-vv + +thingdev.menu.UploadSpeed.115200=115200 +thingdev.menu.UploadSpeed.115200.upload.speed=115200 +thingdev.menu.UploadSpeed.9600=9600 +thingdev.menu.UploadSpeed.9600.upload.speed=9600 +thingdev.menu.UploadSpeed.57600=57600 +thingdev.menu.UploadSpeed.57600.upload.speed=57600 +thingdev.menu.UploadSpeed.256000.windows=256000 +thingdev.menu.UploadSpeed.256000.upload.speed=256000 +thingdev.menu.UploadSpeed.230400.linux=230400 +thingdev.menu.UploadSpeed.230400.macosx=230400 +thingdev.menu.UploadSpeed.230400.upload.speed=230400 +thingdev.menu.UploadSpeed.460800.linux=460800 +thingdev.menu.UploadSpeed.460800.macosx=460800 +thingdev.menu.UploadSpeed.460800.upload.speed=460800 +thingdev.menu.UploadSpeed.512000.windows=512000 +thingdev.menu.UploadSpeed.512000.upload.speed=512000 +thingdev.menu.UploadSpeed.921600=921600 +thingdev.menu.UploadSpeed.921600.upload.speed=921600 + ############################################################## esp210.name=SweetPea ESP-210 diff --git a/cores/esp8266/MD5Builder.cpp b/cores/esp8266/MD5Builder.cpp index a382093a4..dd3d9dd33 100644 --- a/cores/esp8266/MD5Builder.cpp +++ b/cores/esp8266/MD5Builder.cpp @@ -24,43 +24,42 @@ void MD5Builder::addHexString(const char * data){ } bool MD5Builder::addStream(Stream & stream, const size_t total_len) { - const int buf_size = 512; - int bytesleft = total_len; - uint8_t * buf = (uint8_t*) malloc(buf_size); - if(buf) { - while((stream.available() > -1) && (bytesleft > 0)) { + const int buf_size = 512; + int bytesleft = total_len; + uint8_t * buf = (uint8_t*) malloc(buf_size); + if(buf) { + while((stream.available() > -1) && (bytesleft > 0)) { + // get available data size + int sizeAvailable = stream.available(); + if(sizeAvailable) { + int readBytes = sizeAvailable; - // get available data size - int sizeAvailable = stream.available(); - if(sizeAvailable) { - int readBytes = sizeAvailable; - - // read only the asked bytes - if(readBytes > bytesleft) { - readBytes = bytesleft ; - } - - // not read more the buffer can handle - if(readBytes > buf_size) { - readBytes = buf_size; - } - - // read data - int bytesread = stream.readBytes(buf, readBytes); - bytesleft -= bytesread; - if(bytesread > 0) { - MD5Update(&_ctx, buf, bytesread); - } - } - // time for network streams - delay(0); + // read only the asked bytes + if(readBytes > bytesleft) { + readBytes = bytesleft ; } - // not free null ptr - free(buf); - return (bytesleft == 0); - } else { - return false; + + // not read more the buffer can handle + if(readBytes > buf_size) { + readBytes = buf_size; + } + + // read data + int bytesread = stream.readBytes(buf, readBytes); + bytesleft -= bytesread; + if(bytesread > 0) { + MD5Update(&_ctx, buf, bytesread); + } + } + // time for network streams + delay(0); } + // guaranteed not null + free(buf); + return (bytesleft == 0); + } else { + return false; + } } void MD5Builder::calculate(void){ @@ -77,7 +76,7 @@ void MD5Builder::getChars(char * output){ } String MD5Builder::toString(void){ - char out[32]; + char out[33]; getChars(out); return String(out); } \ No newline at end of file diff --git a/cores/esp8266/WMath.cpp b/cores/esp8266/WMath.cpp index da46a3ddb..d56db8e5c 100644 --- a/cores/esp8266/WMath.cpp +++ b/cores/esp8266/WMath.cpp @@ -26,10 +26,11 @@ extern "C" { #include } +#include "esp8266_peri.h" void randomSeed(unsigned long seed) { if(seed != 0) { - srand(seed); + srand((seed ^ RANDOM_REG32)); } } @@ -37,7 +38,7 @@ long random(long howbig) { if(howbig == 0) { return 0; } - return rand() % howbig; + return (rand() ^ RANDOM_REG32) % howbig; } long random(long howsmall, long howbig) { diff --git a/doc/boards.md b/doc/boards.md index 6d2e811b2..7af1d7d6a 100644 --- a/doc/boards.md +++ b/doc/boards.md @@ -9,6 +9,7 @@ title: Supported Hardware * [NodeMCU 1\.0](#nodemcu-10) * [Olimex MOD\-WIFI\-ESP8266\-DEV](#olimex-mod-wifi-esp8266-dev) * [Olimex MOD\-WIFI\-ESP8266](#olimex-mod-wifi-esp8266) + * [Olimex ESP8266\-EVB](#olimex-esp8266-evb) * [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing) * [SweetPea ESP\-210](#sweetpea-esp-210) * [ESPino](#espino) @@ -77,12 +78,28 @@ Since jumper IO0JP is tied to GPIO0, which is PIN 21, you'll have to ground it b UART pins for programming and serial I/O are GPIO1 (TXD, pin 3) and GPIO3 (RXD, pin 4). -Get the board schematics [here](https://github.com/OLIMEX/ESP8266/blob/master/HARDWARE/MOD-WIFI-ESP8266-DEV/MOD-WIFI-ESP8266-DEV_schematic.pdf) +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) ## Olimex MOD-WIFI-ESP8266 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. +## Olimex ESP8266-EVB + +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). + +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. + +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. + +You can find the board schematics [here](https://github.com/OLIMEX/ESP8266/blob/master/HARDWARE/ESP8266-EVB/ESP8266-EVB_Rev_A.pdf). + +[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. + +Board variants include: + * ESP8266-EVB-BAT: comes with built-in LiPo charger and step-up converter + * ESP8266-EVB-BAT-BOX: as above, but enclosd in a plastic box (non-weatherproof) + ## SparkFun ESP8266 Thing ### Product page: https://www.sparkfun.com/products/13231 diff --git a/doc/libraries.md b/doc/libraries.md index ebbbd8453..e749def26 100644 --- a/doc/libraries.md +++ b/doc/libraries.md @@ -142,6 +142,7 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)). - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [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)` +- [Encoder](https://github.com/PaulStoffregen/Encoder) - Arduino library for rotary encoders. Version 1.4 supports ESP8266. - [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). - [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. - [PubSubClient](https://github.com/Imroy/pubsubclient) - MQTT library by @Imroy. diff --git a/doc/ota_updates/a-ota-upload-password-authenticating-ok.png b/doc/ota_updates/a-ota-upload-password-authenticating-ok.png new file mode 100644 index 000000000..052d0da8b Binary files /dev/null and b/doc/ota_updates/a-ota-upload-password-authenticating-ok.png differ diff --git a/doc/ota_updates/a-ota-upload-password-passing-again-upload-ok.png b/doc/ota_updates/a-ota-upload-password-passing-again-upload-ok.png new file mode 100644 index 000000000..cc6ea94dc Binary files /dev/null and b/doc/ota_updates/a-ota-upload-password-passing-again-upload-ok.png differ diff --git a/doc/ota_updates/a-ota-upload-password-passing-upload-ok.png b/doc/ota_updates/a-ota-upload-password-passing-upload-ok.png new file mode 100644 index 000000000..e9254ebec Binary files /dev/null and b/doc/ota_updates/a-ota-upload-password-passing-upload-ok.png differ diff --git a/doc/ota_updates/a-ota-upload-password-prompt.png b/doc/ota_updates/a-ota-upload-password-prompt.png new file mode 100644 index 000000000..e3ecb520d Binary files /dev/null and b/doc/ota_updates/a-ota-upload-password-prompt.png differ diff --git a/doc/ota_updates/ota_updates.md b/doc/ota_updates/ota_updates.md index 43010c2ce..c620ffa09 100644 --- a/doc/ota_updates/ota_updates.md +++ b/doc/ota_updates/ota_updates.md @@ -12,6 +12,7 @@ title: OTA Update * [Application Example](#application-example) * [Classic OTA](#classic-ota) * [ArduinoOTA](#arduinoota) + * [Password Protection](#password-protection) * [Troubleshooting](#troubleshooting) * [Web Browser](#web-browser) * [Requirements](#requirements-1) @@ -228,6 +229,40 @@ IP address: 192.168.1.100 **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. +#### Password Protection + +Protecting your OTA uploads with password is really straightforward. All you need to do, is to include the following statement in your code: + +```cpp +ArduinoOTA.setPassword((const char *)"123"); + +``` + +Where ``` 123 ``` is a sample password that you should replace with your own. + +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: + +![Password prompt for OTA upload](a-ota-upload-password-prompt.png) + +Enter the password and upload should be initiated as usual with the only difference being ``` Authenticating...OK ``` message visible in upload log. + +![ Authenticating...OK during OTA upload](a-ota-upload-password-authenticating-ok.png) + +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. + +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. + +![Verbose upload output with password passing in plan text](a-ota-upload-password-passing-upload-ok.png) + +The picture above shows that the password is visible in log as it is passed to *espota.py* upload script. + +Another example below shows situation when password is changed between uploads. + +![Verbose output when OTA password has been changed between uploads](a-ota-upload-password-passing-again-upload-ok.png) + +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. + + #### Troubleshooting 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: diff --git a/doc/reference.md b/doc/reference.md index a4ab39761..9379ecf63 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -36,7 +36,7 @@ ESP8266 has a single ADC channel available to users. It may be used either to re To read external voltage applied to ADC pin, use `analogRead(A0)`. Input voltage range is 0 — 1.0V. -To read VCC voltage, ADC pin must be kept unconnected. Additionally, the following line has to be added to the sketch: +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: ```c++ ADC_MODE(ADC_VCC); diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index edb09e668..fd11c0360 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -264,7 +264,7 @@ void HTTPClient::setAuthorization(const char * auth) { /** * set the timeout for the TCP connection - * @param timeout unsigned int + * @param timeout unsigned int */ void HTTPClient::setTimeout(uint16_t timeout) { _tcpTimeout = timeout; @@ -273,14 +273,12 @@ void HTTPClient::setTimeout(uint16_t timeout) { } } - - /** * use HTTP1.0 * @param timeout */ void HTTPClient::useHTTP10(bool useHTTP10) { - _useHTTP10 = useHTTP10; + _useHTTP10 = useHTTP10; } /** @@ -305,6 +303,16 @@ int HTTPClient::POST(String payload) { return POST((uint8_t *) payload.c_str(), payload.length()); } +/** + * sendRequest + * @param type const char * "GET", "POST", .... + * @param payload String data for the message body + * @return + */ +int HTTPClient::sendRequest(const char * type, String payload) { + return sendRequest(type, (uint8_t *) payload.c_str(), payload.length()); +} + /** * sendRequest * @param type const char * "GET", "POST", .... @@ -382,7 +390,6 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) { // create buffer for read uint8_t * buff = (uint8_t *) malloc(buff_size); - if(buff) { // read all data from stream and send it to server while(connected() && (stream->available() > -1) && (len > 0 || len == -1)) { @@ -461,8 +468,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) { free(buff); if(size && (int) size != bytesWritten) { - 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!"); + 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!"); return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } else { DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload written: %d\n", bytesWritten); @@ -819,10 +825,12 @@ int HTTPClient::handleHeaderResponse() { if(!connected()) { return HTTPC_ERROR_NOT_CONNECTED; } + String transferEncoding; _returnCode = -1; _size = -1; _transferEncoding = HTTPC_TE_IDENTITY; + unsigned long lastDataTime = millis(); while(connected()) { size_t len = _tcp->available(); @@ -830,6 +838,8 @@ int HTTPClient::handleHeaderResponse() { String headerLine = _tcp->readStringUntil('\n'); headerLine.trim(); // remove \r + lastDataTime = millis(); + DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] RX: '%s'\n", headerLine.c_str()); if(headerLine.startsWith("HTTP/1.")) { @@ -885,6 +895,9 @@ int HTTPClient::handleHeaderResponse() { } } else { + if((millis() - lastDataTime) > _tcpTimeout) { + return HTTPC_ERROR_READ_TIMEOUT; + } delay(0); } } @@ -892,8 +905,6 @@ int HTTPClient::handleHeaderResponse() { return HTTPC_ERROR_CONNECTION_LOST; } - - /** * write one Data Block to Stream * @param stream Stream * diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index 704841a8c..0b865c2a6 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -147,6 +147,7 @@ class HTTPClient { int GET(); int POST(uint8_t * payload, size_t size); int POST(String payload); + int sendRequest(const char * type, String payload); int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0); int sendRequest(const char * type, Stream * stream, size_t size = 0);