Skip to content

Commit 72954ab

Browse files
authored
Merge branch 'master' into bug-esp8266#3795
2 parents 870db92 + c40d8a9 commit 72954ab

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

Diff for: cores/esp8266/uart.c

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ int uart_peek_char(uart_t* uart)
104104

105105
int uart_read_char(uart_t* uart)
106106
{
107+
if(uart == NULL) {
108+
return -1;
109+
}
107110
int data = uart_peek_char(uart);
108111
if(data != -1) {
109112
uart->rx_buffer->rpos = (uart->rx_buffer->rpos + 1) % uart->rx_buffer->size;

Diff for: doc/boards.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This module is sold under many names for around $6.50 on AliExpress and it's one
5858

5959
It's an open hardware design with an ESP-12E core and 4 MB of SPI flash.
6060

61-
Acording to the manufacturer, "with a micro USB cable, you can connect NodeMCU devkit to your laptop and flash it without any trouble". This is more or less true: the board comes with a CP2102 onboard USB to serial adapter which just works, well, the majority of the time. Sometimes flashing fails and you have to reset the board by holding down FLASH +
61+
According to the manufacturer, "with a micro USB cable, you can connect NodeMCU devkit to your laptop and flash it without any trouble". This is more or less true: the board comes with a CP2102 onboard USB to serial adapter which just works, well, the majority of the time. Sometimes flashing fails and you have to reset the board by holding down FLASH +
6262
RST, then releasing FLASH, then releasing RST. This forces the CP2102 device to power cycle and to be re-numbered by Linux.
6363

6464
The board also features a NCP1117 voltage regulator, a blue LED on GPIO16 and a 220k/100k Ohm voltage divider on the ADC input pin.

Diff for: doc/reference.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ Serial
9494
------
9595

9696
``Serial`` object works much the same way as on a regular Arduino. Apart
97-
from hardware FIFO (128 bytes for TX and RX) HardwareSerial has
97+
from hardware FIFO (128 bytes for TX and RX) ``Serial`` has
9898
additional 256-byte TX and RX buffers. Both transmit and receive is
9999
interrupt-driven. Write and read functions only block the sketch
100-
execution when the respective FIFO/buffers are full/empty.
100+
execution when the respective FIFO/buffers are full/empty. Note that
101+
the length of additional 256-bit buffer can be customized.
101102

102103
``Serial`` uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3
103104
(RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling
@@ -121,6 +122,9 @@ instead, call ``Serial1.setDebugOutput(true)``.
121122
You also need to use ``Serial.setDebugOutput(true)`` to enable output
122123
from ``printf()`` function.
123124

125+
The method ``Serial.setRxBufferSize(size_t size)`` allows to define the
126+
receiving buffer depth. The default value is 256.
127+
124128
Both ``Serial`` and ``Serial1`` objects support 5, 6, 7, 8 data bits,
125129
odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the
126130
desired mode, call ``Serial.begin(baudrate, SERIAL_8N1)``,
@@ -142,6 +146,8 @@ current speed. For example
142146
// Will print "Serial is 57600 bps"
143147
Serial.printf("Serial is %d bps", br);
144148
149+
| ``Serial`` and ``Serial1`` objects are both instances of the
150+
``HardwareSerial`` class.
145151
| I've done this also for official ESP8266 `Software
146152
Serial <https://github.com/esp8266/Arduino/blob/master/doc/libraries.md#softwareserial>`__
147153
library, see this `pull

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ void ESP8266WiFiGenericClass::persistent(bool persistent) {
303303
_persistent = persistent;
304304
}
305305

306+
/**
307+
* gets the persistent state
308+
* @return bool
309+
*/
310+
bool ESP8266WiFiGenericClass::getPersistent(){
311+
return _persistent;
312+
}
306313

307314
/**
308315
* set new mode

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ESP8266WiFiGenericClass {
9999

100100
int hostByName(const char* aHostname, IPAddress& aResult);
101101
int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms);
102-
102+
bool getPersistent();
103103
protected:
104104

105105
friend class ESP8266WiFiSTAClass;

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ wl_status_t ESP8266WiFiSTAClass::begin() {
195195
return status();
196196
}
197197

198+
static void
199+
swap(IPAddress &lhs, IPAddress &rhs)
200+
{
201+
IPAddress tmp = lhs;
202+
lhs = rhs;
203+
rhs = tmp;
204+
}
205+
198206

199207
/**
200208
* Change IP configuration settings disabling the dhcp client
@@ -210,6 +218,22 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
210218
return false;
211219
}
212220

221+
//Arduino has a different arg order: ip, dns, gateway, subnet. To allow compatibility, check first octet of 3rd arg. If 255, interpret as ESP order, otherwise Arduino order.
222+
if(subnet[0] != 255)
223+
{
224+
//octet is not 255 => interpret as Arduino order
225+
226+
if(dns1[0] == 0)
227+
{
228+
//arg order is arduino and 4th arg not given => assign it arduino default
229+
dns1 = IPAddress(255,255,255,0);
230+
}
231+
232+
//current order is arduino: ip-dns-gway-subnet
233+
swap(gateway, subnet); //after this, order is ip-gway-dns-subnet
234+
swap(subnet, dns1); //after this, order is ip-gway-subnet-dns (correct ESP order)
235+
}
236+
213237
struct ip_info info;
214238
info.ip.addr = static_cast<uint32_t>(local_ip);
215239
info.gw.addr = static_cast<uint32_t>(gateway);

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class ESP8266WiFiSTAClass {
3939
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
4040
wl_status_t begin();
4141

42+
//The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
43+
//to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't
44+
//work here (see Arduino docs for gway/subnet defaults). In other words: at least 3 args must always be given.
4245
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
4346

4447
bool reconnect();

0 commit comments

Comments
 (0)