Skip to content

Commit 3ff5947

Browse files
committed
Merge pull request #370 from Links2004/esp8266
add better docu and schematics for easy setup the ESP
2 parents 00f4f91 + c0df9b0 commit 3ff5947

File tree

6 files changed

+82
-26
lines changed

6 files changed

+82
-26
lines changed

README.md

+51-12
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ Libraries that don't rely on low-level access to AVR registers should work well.
206206
Pick the correct serial port.
207207
You need to put ESP8266 into bootloader mode before uploading code.
208208

209+
#### Power Supply ####
210+
211+
For stable use of the ESP8266 a power supply with 3V3 and >= 250mA is required.
212+
213+
* Note
214+
- using Power from USB to Serial is may unstable, they not deliver enough current.
215+
216+
#### Serial Adapter ####
217+
218+
There are many different USB to Serial adapters / boards.
219+
220+
* Note
221+
- for full upload management you need RTS and DTR
222+
- the chip need to have 3V3 TTL (5V may damage the chip)
223+
- not all board have all pins of the ICs as breakout (check before order)
224+
- CTS and DSR are not useful for upload (they are Inputs)
225+
226+
* Working ICs
227+
- FT232RL
228+
- CP2102
229+
- may others (drop a comment)
230+
209231
#### Minimal hardware Setup for Bootloading and usage ####
210232

211233
ESPxx Hardware
@@ -226,26 +248,43 @@ ESPxx Hardware
226248
- Reset is also named RSBT or REST (adding PullUp improves the stability of the Module)
227249
- GPIO2 is alternative TX for the boot loader mode
228250

229-
ESP01 example:
230-
231-
![ESP01 connect](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP01_connect.jpg)
251+
###### esp to Serial
252+
![ESP to Serial](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_to_serial.png)
232253

233254
#### Minimal hardware Setup for Bootloading only ####
234255
ESPxx Hardware
235256

236-
| PIN | Resistor | Serial Adapter |
237-
| ------------- | -------- | -------------- |
238-
| VCC | | VCC (3.3V) |
239-
| GND | | GND |
240-
| TX or GPIO2 | | RX |
241-
| RX | | TX |
242-
| GPIO0 | | GND |
257+
| PIN | Resistor | Serial Adapter |
258+
| ------------- | -------- | --------------- |
259+
| VCC | | VCC (3.3V) |
260+
| GND | | GND |
261+
| TX or GPIO2 | | RX |
262+
| RX | | TX |
263+
| GPIO0 | | GND |
243264
| Reset | | RTS* |
244-
| GPIO15 | PullDown | |
245-
| CH_PD | PullUp | |
265+
| GPIO15 | PullDown | |
266+
| CH_PD | PullUp | |
246267

247268
* Note
248269
- if no RTS is used a manual power toggle is needed
270+
271+
#### Minimal hardware Setup for running only ####
272+
273+
ESPxx Hardware
274+
275+
| PIN | Resistor | Power supply |
276+
| ------------- | -------- | --------------- |
277+
| VCC | | VCC (3.3V) |
278+
| GND | | GND |
279+
| GPIO0 | PullUp | |
280+
| GPIO15 | PullDown | |
281+
| CH_PD | PullUp | |
282+
283+
###### minimal
284+
![ESP min](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_min.png)
285+
286+
###### improved stability
287+
![ESP improved stability](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_improved_stability.png)
249288

250289
### Issues and support ###
251290

doc/ESP_improved_stability.png

18 KB
Loading

doc/ESP_min.png

6.46 KB
Loading

doc/ESP_to_serial.png

21.3 KB
Loading

libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ ESP8266WiFiClass::ESP8266WiFiClass()
4646

4747
void ESP8266WiFiClass::mode(WiFiMode m)
4848
{
49+
if(wifi_get_opmode() == (uint8)m) {
50+
return;
51+
}
4952
ETS_UART_INTR_DISABLE();
5053
wifi_set_opmode(m);
5154
ETS_UART_INTR_ENABLE();
@@ -357,10 +360,14 @@ void ESP8266WiFiClass::_scanDone(void* result, int status)
357360

358361
int8_t ESP8266WiFiClass::scanNetworks()
359362
{
360-
if ((wifi_get_opmode() & 1) == 0)//1 and 3 have STA enabled
361-
{
363+
if(_useApMode) {
364+
// turn on AP+STA mode
362365
mode(WIFI_AP_STA);
366+
} else {
367+
// turn on STA mode
368+
mode(WIFI_STA);
363369
}
370+
364371
int status = wifi_station_get_connect_status();
365372
if (status != STATION_GOT_IP && status != STATION_IDLE)
366373
{
@@ -532,9 +539,12 @@ void ESP8266WiFiClass::beginSmartConfig()
532539
if (_smartConfigStarted)
533540
return;
534541

535-
if ((wifi_get_opmode() & 1) == 0)//1 and 3 have STA enabled
536-
{
542+
if(_useApMode) {
543+
// turn on AP+STA mode
537544
mode(WIFI_AP_STA);
545+
} else {
546+
// turn on STA mode
547+
mode(WIFI_STA);
538548
}
539549

540550
_smartConfigStarted = true;

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ wl_status_t ESP8266WiFiMulti::run(void) {
7272

7373
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
7474

75-
7675
bool known = false;
7776
for(uint32_t x = 0; x < APlist.size(); x++) {
7877
WifiAPlist_t entry = APlist[x];
@@ -152,7 +151,17 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
152151

153152
WifiAPlist_t newAP;
154153

155-
newAP.ssid = (char*) malloc(strlen(ssid));
154+
if(!ssid || strlen(ssid) > 31) {
155+
// fail SSID to long or missing!
156+
return false;
157+
}
158+
159+
if(passphrase && strlen(passphrase) > 63) {
160+
// fail passphrase to long!
161+
return false;
162+
}
163+
164+
newAP.ssid = (char*) malloc((strlen(ssid) + 1));
156165

157166
if(!newAP.ssid) {
158167
return false;
@@ -161,16 +170,14 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
161170
strcpy(newAP.ssid, ssid);
162171

163172
if(passphrase && *passphrase != 0x00) {
164-
newAP.passphrase = (char*) malloc(strlen(passphrase));
165-
}
166-
167-
if(!newAP.passphrase) {
168-
free(newAP.ssid);
169-
return false;
173+
newAP.passphrase = (char*) malloc((strlen(passphrase) + 1));
174+
if(!newAP.passphrase) {
175+
free(newAP.ssid);
176+
return false;
177+
}
178+
strcpy(newAP.passphrase, passphrase);
170179
}
171180

172-
strcpy(newAP.passphrase, passphrase);
173-
174181
APlist.push_back(newAP);
175182
return true;
176183
}

0 commit comments

Comments
 (0)