Skip to content

Commit a331927

Browse files
author
Me No Dev
committed
Merge remote-tracking branch 'esp8266/master'
2 parents 8addbe8 + e75c3d8 commit a331927

File tree

7 files changed

+122
-48
lines changed

7 files changed

+122
-48
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ This project brings support for ESP8266 chip to the Arduino environment. It lets
55

66
ESP8266 Arduino core comes with libraries to communicate over WiFi using TCP and UDP, set up HTTP, mDNS, SSDP, and DNS servers, do OTA updates, use a file system in flash memory, work with SD cards, servos, SPI and I2C peripherals.
77

8+
# Contents
9+
- Installing options:
10+
- [Using Boards Manager](#installing-with-boards-manager)
11+
- [Using git version](#using-git-version-)
12+
- [Using stable version with PlatformIO](#using-stable-version-with-platformio)
13+
- [Documentation](#documentation)
14+
- [Issues and support](#issues-and-support)
15+
- [Contributing](#contributing)
16+
- [License and credits](#license-and-credits)
17+
818
### Installing with Boards Manager ###
919

1020
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).

doc/platformio.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ platformio boards espressif
2828
# Initialise base project
2929
#
3030
platformio init --board %TYPE%(see above)
31+
# for example, initialise project for ESP8266 ESP-12E board (NodeMCU)
32+
platformio init --board esp12e
3133

3234
# The next files/directories will be created in myproject
3335
# platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
@@ -39,16 +41,44 @@ platformio init --board %TYPE%(see above)
3941
- Place your source code to `src` directory
4042
- Build/Upload project
4143

42-
```
44+
```bash
4345
# process/build project
4446
platformio run
4547

4648
# build+upload firmware
4749
platformio run --target upload
50+
```
51+
52+
## OTA firmware uploading
4853

49-
# build+upload firmware via OTA
54+
There are 2 options:
55+
56+
- Directly specify `--upoad-port` in command line
57+
```bash
5058
platformio run --target upload --upload-port IP_ADDRESS_HERE
5159
```
60+
- Specify [upload_port](http://docs.platformio.org/en/latest/projectconf.html#upload-port) option in `platformio.ini`
61+
```ini
62+
[env:***]
63+
...
64+
upload_port = IP_ADDRESS_HERE
65+
```
66+
67+
### Authentication and upload options
68+
69+
You can pass additional options/flags to OTA uploader using [upload_flags](http://docs.platformio.org/en/latest/projectconf.html#upload-flags) option in `platformio.ini`
70+
```ini
71+
[env:***]
72+
upload_flags = --port=8266
73+
```
74+
75+
Availalbe flags
76+
- `--port=ESP_PORT` ESP8266 ota Port. Default 8266
77+
- `--auth=AUTH` Set authentication password
78+
- `--spiffs` Use this option to transmit a SPIFFS image and do not flash the module
79+
80+
For the full list with availalbe options please run this command `~/.platformio/packages/framework-arduinoespressif/tools/espota.py -h`.
81+
5282

5383
## IDE Integration
5484
In addition, PlatformIO [can be integrated into the popular IDEs](http://docs.platformio.org/en/latest/ide.html). For example, initialise project for Espressif ESP8266 ESP-01 board and Eclipse IDE

libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void loop() {
6060
}
6161

6262
http.end();
63-
6463
}
6564

6665
delay(1000);

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "ESP8266HTTPClient.h"
3232

33-
3433
/**
3534
* constractor
3635
*/
@@ -117,7 +116,7 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
117116
if(index >= 0) {
118117
// auth info
119118
String auth = host.substring(0, index);
120-
host.remove(0, index +1); // remove auth part including @
119+
host.remove(0, index + 1); // remove auth part including @
121120
_base64Authorization = base64::encode(auth);
122121
}
123122

@@ -335,8 +334,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
335334
return HTTPC_ERROR_SEND_HEADER_FAILED;
336335
}
337336

338-
// create buffer for read
339-
uint8_t buff[1460] = { 0 };
337+
size_t buff_size = HTTP_TCP_BUFFER_SIZE;
340338

341339
int len = size;
342340
int bytesWritten = 0;
@@ -345,34 +343,51 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
345343
len = -1;
346344
}
347345

348-
// read all data from stream and send it to server
349-
while(connected() && stream->available() && (len > 0 || len == -1)) {
346+
// if possible create smaller buffer then HTTP_TCP_BUFFER_SIZE
347+
if((len > 0) && (len < HTTP_TCP_BUFFER_SIZE)) {
348+
buff_size = len;
349+
}
350+
351+
// create buffer for read
352+
uint8_t * buff = (uint8_t *) malloc(buff_size);
353+
354+
355+
if(buff) {
356+
// read all data from stream and send it to server
357+
while(connected() && stream->available() && (len > 0 || len == -1)) {
350358

351-
// get available data size
352-
size_t s = stream->available();
359+
// get available data size
360+
size_t s = stream->available();
353361

354-
if(s) {
355-
int c = stream->readBytes(buff, ((s > sizeof(buff)) ? sizeof(buff) : s));
362+
if(s) {
363+
int c = stream->readBytes(buff, ((s > buff_size) ? buff_size : s));
356364

357-
// write it to Stream
358-
bytesWritten += _tcp->write((const uint8_t *)buff, c);
365+
// write it to Stream
366+
bytesWritten += _tcp->write((const uint8_t *) buff, c);
359367

360-
if(len > 0) {
361-
len -= c;
368+
if(len > 0) {
369+
len -= c;
370+
}
371+
372+
delay(0);
373+
} else {
374+
delay(1);
362375
}
376+
}
363377

364-
delay(0);
378+
free(buff);
379+
380+
if(size && (int) size != bytesWritten) {
381+
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, _size);
382+
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
383+
return HTTPC_ERROR_SEND_PAYLOAD_FAILED;
365384
} else {
366-
delay(1);
385+
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload written: %d\n", bytesWritten);
367386
}
368-
}
369387

370-
if(size && (int)size != bytesWritten) {
371-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, _size);
372-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
373-
return HTTPC_ERROR_SEND_PAYLOAD_FAILED;
374388
} else {
375-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload written: %d\n", bytesWritten);
389+
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] too less ram! need " HTTP_TCP_BUFFER_SIZE);
390+
return HTTPC_ERROR_TOO_LESS_RAM;
376391
}
377392

378393
// handle Server Response (Header)
@@ -434,35 +449,50 @@ int HTTPClient::writeToStream(Stream * stream) {
434449
int len = _size;
435450
int bytesWritten = 0;
436451

452+
size_t buff_size = HTTP_TCP_BUFFER_SIZE;
453+
454+
// if possible create smaller buffer then HTTP_TCP_BUFFER_SIZE
455+
if((len > 0) && (len < HTTP_TCP_BUFFER_SIZE)) {
456+
buff_size = len;
457+
}
458+
437459
// create buffer for read
438-
uint8_t buff[1460] = { 0 };
460+
uint8_t * buff = (uint8_t *) malloc(buff_size);
439461

440-
// read all data from server
441-
while(connected() && (len > 0 || len == -1)) {
462+
if(buff) {
463+
// read all data from server
464+
while(connected() && (len > 0 || len == -1)) {
442465

443-
// get available data size
444-
size_t size = _tcp->available();
466+
// get available data size
467+
size_t size = _tcp->available();
445468

446-
if(size) {
447-
int c = _tcp->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
469+
if(size) {
470+
int c = _tcp->readBytes(buff, ((size > buff_size) ? buff_size : size));
448471

449-
// write it to Stream
450-
bytesWritten += stream->write(buff, c);
472+
// write it to Stream
473+
bytesWritten += stream->write(buff, c);
451474

452-
if(len > 0) {
453-
len -= c;
454-
}
475+
if(len > 0) {
476+
len -= c;
477+
}
455478

456-
delay(0);
457-
} else {
458-
delay(1);
479+
delay(0);
480+
} else {
481+
delay(1);
482+
}
459483
}
460-
}
461484

462-
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] connection closed or file end (written: %d).\n", bytesWritten);
485+
free(buff);
463486

464-
if(_size && _size != bytesWritten) {
465-
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] bytesWritten %d and size %d mismatch!.\n", bytesWritten, _size);
487+
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] connection closed or file end (written: %d).\n", bytesWritten);
488+
489+
if(_size && _size != bytesWritten) {
490+
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] bytesWritten %d and size %d mismatch!.\n", bytesWritten, _size);
491+
}
492+
493+
} else {
494+
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] too less ram! need " HTTP_TCP_BUFFER_SIZE);
495+
return HTTPC_ERROR_TOO_LESS_RAM;
466496
}
467497

468498
end();
@@ -509,12 +539,13 @@ String HTTPClient::errorToString(int error) {
509539
return String("no stream");
510540
case HTTPC_ERROR_NO_HTTP_SERVER:
511541
return String("no HTTP server");
542+
case HTTPC_ERROR_TOO_LESS_RAM:
543+
return String("too less ram");
512544
default:
513545
return String();
514546
}
515547
}
516548

517-
518549
/**
519550
* adds Header to the request
520551
* @param name

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#define HTTPC_ERROR_CONNECTION_LOST (-5)
4242
#define HTTPC_ERROR_NO_STREAM (-6)
4343
#define HTTPC_ERROR_NO_HTTP_SERVER (-7)
44+
#define HTTPC_ERROR_TOO_LESS_RAM (-8)
45+
46+
/// size for the stream handling
47+
#define HTTP_TCP_BUFFER_SIZE (1460)
4448

4549
/// HTTP codes see RFC7231
4650
typedef enum {

libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void ESP8266WiFiClass::scanDelete()
561561
_scanComplete = false;
562562
}
563563

564-
int8_t ESP8266WiFiClass::scanNetworks(bool async)
564+
int8_t ESP8266WiFiClass::scanNetworks(bool async, bool show_hidden)
565565
{
566566
if(ESP8266WiFiClass::_scanStarted) {
567567
return WIFI_SCAN_RUNNING;
@@ -589,7 +589,7 @@ int8_t ESP8266WiFiClass::scanNetworks(bool async)
589589
config.ssid = 0;
590590
config.bssid = 0;
591591
config.channel = 0;
592-
config.show_hidden = 0;
592+
config.show_hidden = show_hidden;
593593
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiClass::_scanDone))) {
594594
ESP8266WiFiClass::_scanComplete = false;
595595
ESP8266WiFiClass::_scanStarted = true;

libraries/ESP8266WiFi/src/ESP8266WiFi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class ESP8266WiFiClass
240240
*
241241
* return: Number of discovered networks
242242
*/
243-
int8_t scanNetworks(bool async = false);
243+
int8_t scanNetworks(bool async = false, bool show_hidden = false);
244244

245245
/*
246246
* Return the SSID discovered during the network scan.

0 commit comments

Comments
 (0)