Skip to content

Commit 3d14b12

Browse files
author
ficeto
committed
Merge pull request #33 from esp8266/esp8266
pull master
2 parents b5a8788 + b39e265 commit 3d14b12

File tree

6 files changed

+223
-69
lines changed

6 files changed

+223
-69
lines changed

README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Arduino-compatible IDE with ESP8266 support
22
===========================================
33

44
![Linux build status](http://img.shields.io/travis/igrr/Arduino.svg)
5+
[![Donate](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/webscr?cmd=_s-xclick&hosted_button_id=4M56YCWV6PX66)
56

67
This project brings support for ESP8266 chip to the Arduino environment. ESP8266WiFi library bundled with this project has the same interface as the WiFi Shield library, making it easy to re-use existing code and libraries.
78

@@ -14,6 +15,8 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package
1415
- Enter ```http://arduino.esp8266.com/package_esp8266com_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.
1516
- Open Boards Manager from Tools > Board menu and install *esp8266* platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).
1617

18+
### [Change log](hardware/esp8266com/esp8266/changes.md)
19+
1720
### Building latest version from source ###
1821
```
1922
$ git clone https://github.com/esp8266/Arduino.git
@@ -41,7 +44,7 @@ GPIO16 can be ```INPUT```, ```OUTPUT``` or ```INPUT_PULLDOWN```.
4144
```analogRead(A0)``` reads the value of the ADC channel connected to the TOUT pin.
4245

4346
```analogWrite(pin, value)``` enables software PWM on the given pin. PWM may be used on pins 0 to 15.
44-
Call ```analogWrite(pin, 0)``` to disable PWM on the pin.
47+
Call ```analogWrite(pin, 0)``` to disable PWM on the pin. ```value``` may be in range from 0 to ```PWMRANGE```, which is currently equal to 1023.
4548

4649
Pin interrupts are supported through ```attachInterrupt```, ```detachInterrupt``` functions.
4750
Interrupts may be attached to any GPIO pin, except GPIO16. Standard Arduino interrupt
@@ -85,7 +88,7 @@ Both ```Serial``` and ```Serial1``` objects support 5, 6, 7, 8 data bits, odd (O
8588
#### Progmem ####
8689

8790
The Program memory features work much the same way as on a regular Arduino; placing read only data and strings in read only memory and freeing heap for your application.
88-
The important difference is that on the esp8266 the literal strings are not pooled. This means that the same literal string defined inside a ```F("")``` and/or ```PSTR("")``` will take up space for each instance in the code. So you will need to manage the duplicate strings yourself.
91+
The important difference is that on the esp8266 the literal strings are not pooled. This means that the same literal string defined inside a ```F("")``` and/or ```PSTR("")``` will take up space for each instance in the code. So you will need to manage the duplicate strings yourself.
8992

9093
#### WiFi(ESP8266WiFi library) ####
9194

@@ -171,8 +174,8 @@ Several APIs may be used to get flash chip info:
171174
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
172175

173176
Library was adapted to work with ESP8266 by including register definitions into OneWire.h
174-
Note that if you have OneWire library in your Arduino/libraries folder, it will be used
175-
instead of the one that comes with the Arduino IDE (this one).
177+
Note that if you already have OneWire library in your Arduino/libraries folder, it will be used
178+
instead of the one that comes with this package.
176179

177180
#### mDNS responder (ESP8266mDNS library) ####
178181

@@ -185,11 +188,12 @@ See attached example and library README file for details.
185188
Libraries that don't rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:
186189

187190
- [aREST](https://github.com/marcoschwartz/aREST) REST API handler library.
188-
- [PubSubClient](https://github.com/knolleary/pubsubclient) MQTT library. Use this [sample](https://gist.github.com/igrr/7f7e7973366fc01d6393) to get started.
191+
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
189192
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
190193
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
191194
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.
192195
- [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266.
196+
- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)).
193197

194198
#### Upload via serial port ####
195199
Pick the correct serial port.
@@ -253,3 +257,7 @@ Espressif SDK included in this build is under Espressif Public License.
253257
Esptool written by Christian Klippel is licensed under GPLv2, currently maintained by Ivan Grokhotkov: https://github.com/igrr/esptool-ck.
254258

255259
ESP8266 core support, ESP8266WiFi, Ticker, ESP8266WebServer libraries were written by Ivan Grokhotkov, [email protected].
260+
261+
[SPI Flash File System (SPIFFS)](https://github.com/pellepl/spiffs) written by Peter Andersson is used in this project. It is distributed under MIT license.
262+
263+

build/build_board_manager_package.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ cat << EOF > package_esp8266com_index.json
8181
},
8282
{
8383
"host":"x86_64-apple-darwin",
84-
"url":"https://github.com/igrr/esptool-ck/releases/download/0.4.4/esptool-0.4.4-osx.tar.gz",
85-
"archiveFileName":"esptool-0.4.4-osx.tar.gz",
86-
"checksum":"SHA-256:bb2a58c3583f9dcb0d3e7611531a0f3a29c21a4a1c442987bb29d07408824dfe",
87-
"size":"12145"
84+
"url":"http://arduino.esp8266.com/esptool-0.4.4-5-g744c44d-osx.tar.gz",
85+
"archiveFileName":"esptool-0.4.4-5-g744c44d-osx.tar.gz",
86+
"checksum":"SHA-256:d8bc920e046fcc668b31cda63ac5553b4c07a6db12bfd0abc9005fc94628afcb",
87+
"size":"12133"
8888
},
8989
{
9090
"host":"x86_64-pc-linux-gnu",
@@ -115,10 +115,10 @@ cat << EOF > package_esp8266com_index.json
115115
},
116116
{
117117
"host":"x86_64-apple-darwin",
118-
"url":"http://arduino.esp8266.com/osx-xtensa-lx106-elf-gb404fb9.tar.gz",
119-
"archiveFileName":"osx-xtensa-lx106-elf-gb404fb9.tar.gz",
120-
"checksum":"SHA-256:540be2ca32637584463a4a4d04717f6c79c7355e336b8c3578b0947218cf92b9",
121-
"size":"35189446"
118+
"url":"http://arduino.esp8266.com/osx-xtensa-lx106-elf-gb404fb9-2.tar.gz",
119+
"archiveFileName":"osx-xtensa-lx106-elf-gb404fb9-2.tar.gz",
120+
"checksum":"SHA-256:0cf150193997bd1355e0f49d3d49711730035257bc1aee1eaaad619e56b9e4e6",
121+
"size":"35385382"
122122
},
123123
{
124124
"host":"x86_64-pc-linux-gnu",
+15-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
# Change log
12

3+
## 1.6.4-673-g8cd3697
4+
May 22, 2015
25

3-
# Current version
6+
### Tools
7+
8+
- Add 32-bit Linux toolchain.
9+
- Rebuild toolchain and esptool with support for OS X down to 10.6.
10+
11+
### Libraries
412

5-
- Add 32-bit Linux toolchain
613
- Better connection handling in ESP8266WebServer.
714
The server now sends Content-Length and Connection: close headers,
815
then waits for the client to disconnect. By not closing the connection
9-
actively, server avoids TIME_WAIT TCP state, and the TCP stack is able to
16+
actively, server avoids TIME_WAIT TCP state, and TCP stack is able to
1017
release the memory immediately, without waiting for 2xMSL period.
1118
If the client doesn't disconnect in 2000ms, the server closes the connection
1219
actively.
1320
- Add Hash library, which has a function to calculate SHA1 hash.
21+
- SD, Adafruit_ILI9341, and OneWire libraries are now bundled.
22+
- Fix incorrect sector calculation in EEPROM library.
1423

1524
---
1625

17-
# 1.6.4-g545ffde
18-
19 May, 2015
26+
## 1.6.4-628-g545ffde
27+
May 19, 2015
1928

20-
- Initial release of board manager package
29+
- Initial release of Boards Manager package for ESP8266 platform.
2130

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+102-30
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ extern "C" void esp_schedule();
3838
extern "C" void esp_yield();
3939

4040
ESP8266WiFiClass::ESP8266WiFiClass()
41+
: _useApMode(false)
42+
, _useClientMode(false)
4143
{
42-
4344
}
4445

4546
void ESP8266WiFiClass::mode(WiFiMode m)
@@ -49,34 +50,56 @@ void ESP8266WiFiClass::mode(WiFiMode m)
4950
ETS_UART_INTR_ENABLE();
5051
}
5152

52-
53-
int ESP8266WiFiClass::begin(const char* ssid)
54-
{
55-
return begin(ssid, 0);
53+
int ESP8266WiFiClass::begin(char* ssid, char *passphrase, int32_t channel, uint8_t bssid[6]){
54+
return begin((const char*) ssid, (const char*) passphrase, channel, bssid);
5655
}
5756

57+
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){
58+
_useClientMode = true;
5859

59-
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase)
60-
{
61-
if ((wifi_get_opmode() & 1) == 0)//1 and 3 have STA enabled
62-
{
60+
if(_useApMode) {
6361
// turn on AP+STA mode
6462
mode(WIFI_AP_STA);
63+
} else {
64+
// turn on STA mode
65+
mode(WIFI_STA);
66+
}
67+
68+
if(!ssid || strlen(ssid) > 31) {
69+
// fail SSID to long or missing!
70+
return WL_CONNECT_FAILED;
71+
}
72+
73+
if(passphrase && strlen(passphrase) > 63) {
74+
// fail passphrase to long!
75+
return WL_CONNECT_FAILED;
6576
}
6677

6778
struct station_config conf;
6879
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
69-
if (passphrase)
80+
81+
if (passphrase) {
7082
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
71-
else
83+
} else {
7284
*conf.password = 0;
85+
}
7386

74-
conf.bssid_set = 0;
87+
if (bssid) {
88+
conf.bssid_set = 1;
89+
memcpy((void *) &conf.bssid[0], (void *) bssid, 6);
90+
} else {
91+
conf.bssid_set = 0;
92+
}
7593

7694
ETS_UART_INTR_DISABLE();
7795
wifi_station_set_config(&conf);
7896
wifi_station_connect();
7997
ETS_UART_INTR_ENABLE();
98+
99+
if(channel > 0 && channel <= 13) {
100+
wifi_set_channel(channel);
101+
}
102+
80103
wifi_station_dhcpc_start();
81104
return status();
82105
}
@@ -120,10 +143,22 @@ void ESP8266WiFiClass::softAP(const char* ssid)
120143

121144
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel)
122145
{
123-
if (wifi_get_opmode() < WIFI_AP)//will be OFF or STA
124-
{
146+
if(_useClientMode) {
125147
// turn on AP+STA mode
126148
mode(WIFI_AP_STA);
149+
} else {
150+
// turn on STA mode
151+
mode(WIFI_AP);
152+
}
153+
154+
if(!ssid || strlen(ssid) > 31) {
155+
// fail SSID to long or missing!
156+
return;
157+
}
158+
159+
if(passphrase && strlen(passphrase) > 63) {
160+
// fail passphrase to long!
161+
return;
127162
}
128163

129164
struct softap_config conf;
@@ -209,22 +244,16 @@ char* ESP8266WiFiClass::SSID()
209244
return reinterpret_cast<char*>(conf.ssid);
210245
}
211246

212-
// uint8_t* ESP8266WiFiClass::BSSID(uint8_t* bssid)
213-
// {
214-
// uint8_t* _bssid = WiFiDrv::getCurrentBSSID();
215-
// memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
216-
// return bssid;
217-
// }
218-
219-
// int32_t ESP8266WiFiClass::RSSI()
220-
// {
221-
// return WiFiDrv::getCurrentRSSI();
222-
// }
247+
uint8_t* ESP8266WiFiClass::BSSID(void)
248+
{
249+
static struct station_config conf;
250+
wifi_station_get_config(&conf);
251+
return reinterpret_cast<uint8_t*>(conf.bssid);
252+
}
223253

224-
// uint8_t ESP8266WiFiClass::encryptionType()
225-
// {
226-
// return WiFiDrv::getCurrentEncryptionType();
227-
// }
254+
int32_t ESP8266WiFiClass::Channel(void) {
255+
return wifi_get_channel();
256+
}
228257

229258
extern "C"
230259
{
@@ -298,7 +327,7 @@ int8_t ESP8266WiFiClass::scanNetworks()
298327

299328
void * ESP8266WiFiClass::_getScanInfoByIndex(int i)
300329
{
301-
if (!ESP8266WiFiClass::_scanResult || i > ESP8266WiFiClass::_scanCount)
330+
if (!ESP8266WiFiClass::_scanResult || (size_t)i > ESP8266WiFiClass::_scanCount)
302331
{
303332
return 0;
304333
}
@@ -315,6 +344,49 @@ const char* ESP8266WiFiClass::SSID(uint8_t i)
315344
return reinterpret_cast<const char*>(it->ssid);
316345
}
317346

347+
uint8_t * ESP8266WiFiClass::BSSID(uint8_t i)
348+
{
349+
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
350+
if (!it)
351+
return 0;
352+
353+
return it->bssid;
354+
}
355+
356+
int32_t ESP8266WiFiClass::Channel(uint8_t i)
357+
{
358+
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
359+
if (!it)
360+
return 0;
361+
362+
return it->channel;
363+
}
364+
365+
bool ESP8266WiFiClass::isHidden(uint8_t i)
366+
{
367+
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
368+
if (!it)
369+
return false;
370+
371+
return (it->is_hidden != 0);
372+
}
373+
374+
bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel, bool &isHidden)
375+
{
376+
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
377+
if (!it)
378+
return false;
379+
380+
ssid = (const char*)it->ssid;
381+
encType = encryptionType(i);
382+
rssi = it->rssi;
383+
bssid = it->bssid; // move ptr
384+
channel = it->channel;
385+
isHidden = (it->is_hidden != 0);
386+
387+
return true;
388+
}
389+
318390
int32_t ESP8266WiFiClass::RSSI(uint8_t i)
319391
{
320392
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));

0 commit comments

Comments
 (0)