From bc37b9ea6856225055088d1afc6c780b807895c9 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Thu, 21 May 2015 21:10:45 +0200 Subject: [PATCH 1/8] ESP8266WiFi extended functions - begin changes allow setting BSSID/MAC and Channel of an AP for faster connection (#261) now checks if ssid and passphrase to big selecting Wifi mode in better way (fix for #28) - ESP8266WiFiMulti uses the new functions to auto select best AP even in a multi AP WiFi network (more the one AP has same SSID) - add new functions to get current Connected AP: uint8_t * BSSID(void); int32_t Channel(void); - add new functions to get infos from scanned networks: uint8_t * BSSID(uint8_t networkItem); int32_t Channel(uint8_t networkItem); bool isHidden(uint8_t networkItem); bool getNetworkInfo(uint8_t networkItem, const char** ssid, uint8_t * encryptionType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden); --- libraries/ESP8266WiFi/src/ESP8266WiFi.cpp | 136 +++++++++++++----- libraries/ESP8266WiFi/src/ESP8266WiFi.h | 76 ++++++++-- .../ESP8266WiFi/src/ESP8266WiFiMulti.cpp | 27 +++- 3 files changed, 188 insertions(+), 51 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp index 115b23763..372df9ed0 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp @@ -39,7 +39,8 @@ extern "C" void esp_yield(); ESP8266WiFiClass::ESP8266WiFiClass() { - + useApMode = false; + useClientMode = false; } void ESP8266WiFiClass::mode(WiFiMode m) @@ -49,34 +50,56 @@ void ESP8266WiFiClass::mode(WiFiMode m) ETS_UART_INTR_ENABLE(); } - -int ESP8266WiFiClass::begin(const char* ssid) -{ - return begin(ssid, 0); +int ESP8266WiFiClass::begin(char* ssid, char *passphrase, int32_t channel, uint8_t bssid[6]){ + return begin((const char*) ssid, (const char*) passphrase, channel, bssid); } +int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){ + useClientMode = true; -int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase) -{ - if ((wifi_get_opmode() & 1) == 0)//1 and 3 have STA enabled - { + if(useApMode) { // turn on AP+STA mode mode(WIFI_AP_STA); + } else { + // turn on STA mode + mode(WIFI_STA); + } + + if(!ssid || strlen(ssid) > 31) { + // fail SSID to long or missing! + return WL_CONNECT_FAILED; + } + + if(passphrase && strlen(passphrase) > 63) { + // fail passphrase to long! + return WL_CONNECT_FAILED; } struct station_config conf; strcpy(reinterpret_cast(conf.ssid), ssid); - if (passphrase) - strcpy(reinterpret_cast(conf.password), passphrase); - else - *conf.password = 0; - conf.bssid_set = 0; + if (passphrase) { + strcpy(reinterpret_cast(conf.password), passphrase); + } else { + *conf.password = 0; + } + + if (bssid) { + conf.bssid_set = 1; + memcpy((void *) &conf.bssid[0], (void *) bssid, 6); + } else { + conf.bssid_set = 0; + } ETS_UART_INTR_DISABLE(); wifi_station_set_config(&conf); wifi_station_connect(); ETS_UART_INTR_ENABLE(); + + if(channel > 0 && channel <= 13) { + wifi_set_channel(channel); + } + wifi_station_dhcpc_start(); return status(); } @@ -120,10 +143,22 @@ void ESP8266WiFiClass::softAP(const char* ssid) void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel) { - if (wifi_get_opmode() < WIFI_AP)//will be OFF or STA - { + if(useClientMode) { // turn on AP+STA mode mode(WIFI_AP_STA); + } else { + // turn on STA mode + mode(WIFI_AP); + } + + if(!ssid || strlen(ssid) > 31) { + // fail SSID to long or missing! + return; + } + + if(passphrase && strlen(passphrase) > 63) { + // fail passphrase to long! + return; } struct softap_config conf; @@ -209,22 +244,16 @@ char* ESP8266WiFiClass::SSID() return reinterpret_cast(conf.ssid); } -// uint8_t* ESP8266WiFiClass::BSSID(uint8_t* bssid) -// { -// uint8_t* _bssid = WiFiDrv::getCurrentBSSID(); -// memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH); -// return bssid; -// } +uint8_t* ESP8266WiFiClass::BSSID(void) +{ + static struct station_config conf; + wifi_station_get_config(&conf); + return reinterpret_cast(conf.bssid); +} -// int32_t ESP8266WiFiClass::RSSI() -// { -// return WiFiDrv::getCurrentRSSI(); -// } - -// uint8_t ESP8266WiFiClass::encryptionType() -// { -// return WiFiDrv::getCurrentEncryptionType(); -// } +int32_t ESP8266WiFiClass::Channel(void) { + return wifi_get_channel(); +} extern "C" { @@ -298,7 +327,7 @@ int8_t ESP8266WiFiClass::scanNetworks() void * ESP8266WiFiClass::_getScanInfoByIndex(int i) { - if (!ESP8266WiFiClass::_scanResult || i > ESP8266WiFiClass::_scanCount) + if (!ESP8266WiFiClass::_scanResult || (size_t)i > ESP8266WiFiClass::_scanCount) { return 0; } @@ -315,6 +344,49 @@ const char* ESP8266WiFiClass::SSID(uint8_t i) return reinterpret_cast(it->ssid); } +uint8_t * ESP8266WiFiClass::BSSID(uint8_t i) +{ + struct bss_info* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) + return 0; + + return it->bssid; +} + +int32_t ESP8266WiFiClass::Channel(uint8_t i) +{ + struct bss_info* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) + return 0; + + return it->channel; +} + +bool ESP8266WiFiClass::isHidden(uint8_t i) +{ + struct bss_info* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) + return false; + + return (it->is_hidden != 0); +} + +bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, const char** ssid, uint8_t * encType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden) +{ + struct bss_info* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) + return false; + + *ssid = (const char*) &it->ssid[0]; // move ptr + *encType = encryptionType(i); + *RSSI = it->rssi; + *BSSID = &it->bssid[0]; // move ptr + *channel = it->channel; + *isHidden = (it->is_hidden != 0); + + return true; +} + int32_t ESP8266WiFiClass::RSSI(uint8_t i) { struct bss_info* it = reinterpret_cast(_getScanInfoByIndex(i)); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/libraries/ESP8266WiFi/src/ESP8266WiFi.h index feb18abf8..caefbc7df 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -42,21 +42,18 @@ public: void mode(WiFiMode); - - /* Start Wifi connection for OPEN networks - * - * param ssid: Pointer to the SSID string. + /** + * Start Wifi connection + * if passphrase is set the most secure supported mode will be automatically selected + * @param ssid const char* Pointer to the SSID string. + * @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal). + * @param bssid uint8_t[6] Optional. BSSID / MAC of AP + * @param channel Optional. Channel of AP + * @return */ - int begin(const char* ssid); + int begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, uint8_t bssid[6] = NULL); + int begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, uint8_t bssid[6] = NULL); - /* Start Wifi connection with passphrase - * the most secure supported mode will be automatically selected - * - * param ssid: Pointer to the SSID string. - * param passphrase: Passphrase. Valid characters in a passphrase - * must be between ASCII 32-126 (decimal). - */ - int begin(const char* ssid, const char *passphrase); /* Wait for Wifi connection to reach a result * returns the status reached or disconnect if STA is off @@ -151,6 +148,20 @@ public: */ char* SSID(); + /* + * Return the current bssid / mac associated with the network if configured + * + * return: bssid string + */ + uint8_t * BSSID(void); + + /* + * Return the current channel associated with the network + * + * return: channel + */ + int32_t Channel(void); + /* * Return the current network RSSI. Note: this is just a stub, there is no way to * get the RSSI in the Espressif SDK yet. @@ -194,6 +205,42 @@ public: */ int32_t RSSI(uint8_t networkItem); + + /** + * return MAC / BSSID of scanned wifi + * @param networkItem specify from which network item want to get the information + * @return uint8_t * to MAC / BSSID of scanned wifi + */ + uint8_t * BSSID(uint8_t networkItem); + + /** + * return Channel of scanned wifi + * @param networkItem specify from which network item want to get the information + * @return uint32_t Channel of scanned wifi + */ + int32_t Channel(uint8_t networkItem); + + /** + * return if the scanned wifi is Hidden (no SSID) + * @param networkItem specify from which network item want to get the information + * @return bool (true == hidden) + */ + bool isHidden(uint8_t networkItem); + + /** + * loads all infos from a scanned wifi in to the ptr parameters + * @param networkItem uint8_t + * @param ssid const char** + * @param encryptionType uint8_t * + * @param RSSI int32_t * + * @param BSSID uint8_t ** + * @param channel int32_t * + * @param isHidden bool * + * @return (true if ok) + */ + bool getNetworkInfo(uint8_t networkItem, const char** ssid, uint8_t * encryptionType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden); + + /* * Return Connection status. * @@ -243,6 +290,9 @@ protected: static void _smartConfigDone(void* result); bool _smartConfigStarted = false; + bool useApMode; + bool useClientMode; + static size_t _scanCount; static void* _scanResult; diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp index 3b878020f..de14a0cb5 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp @@ -44,6 +44,8 @@ wl_status_t ESP8266WiFiMulti::run(void) { WifiAPlist_t bestNetwork { NULL, NULL }; int bestNetworkDb = INT_MIN; + uint8 bestBSSID[6]; + int32_t bestChannel; // WiFi.scanNetworks will return the number of networks found int8_t n = WiFi.scanNetworks(); @@ -56,9 +58,16 @@ wl_status_t ESP8266WiFiMulti::run(void) { } else { DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", n); for(int8_t i = 0; i < n; ++i) { - const char * ssid_scan = WiFi.SSID(i); - int32_t rssi_scan = WiFi.RSSI(i); - uint8_t sec_scan = WiFi.encryptionType(i); + + const char * ssid_scan; + int32_t rssi_scan; + uint8_t sec_scan; + uint8_t * BSSID_scan; + int32_t chan_scan; + bool hidden_scan; + + WiFi.getNetworkInfo(i, &ssid_scan, &sec_scan, &rssi_scan, &BSSID_scan, &chan_scan, &hidden_scan); + bool known = false; for(uint32_t x = 0; x < APlist.size(); x++) { @@ -69,7 +78,9 @@ wl_status_t ESP8266WiFiMulti::run(void) { if(rssi_scan > bestNetworkDb) { // best network if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan bestNetworkDb = rssi_scan; + bestChannel = chan_scan; memcpy((void*) &bestNetwork, (void*) &entry, sizeof(bestNetwork)); + memcpy((void*) &bestBSSID, (void*) BSSID_scan, sizeof(bestBSSID)); } } break; @@ -82,7 +93,7 @@ wl_status_t ESP8266WiFiMulti::run(void) { DEBUG_WIFI_MULTI(" "); } - DEBUG_WIFI_MULTI(" %d: %s (%d) %c\n", i, ssid_scan, rssi_scan, (sec_scan == ENC_TYPE_NONE) ? ' ' : '*'); + DEBUG_WIFI_MULTI(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c\n", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan, rssi_scan, (sec_scan == ENC_TYPE_NONE) ? ' ' : '*'); delay(0); } } @@ -91,9 +102,9 @@ wl_status_t ESP8266WiFiMulti::run(void) { delay(0); if(bestNetwork.ssid) { - DEBUG_WIFI_MULTI("[WIFI] Connecting SSID: %s (%d)\n", bestNetwork.ssid, bestNetworkDb); + DEBUG_WIFI_MULTI("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channal: %d (%d)\n", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb); - WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase); + WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID); status = WiFi.status(); // wait for connection or fail @@ -103,12 +114,16 @@ wl_status_t ESP8266WiFiMulti::run(void) { } IPAddress ip; + uint8_t * mac; switch(status) { case WL_CONNECTED: ip = WiFi.localIP(); + mac = WiFi.BSSID(); DEBUG_WIFI_MULTI("[WIFI] Connecting done.\n"); DEBUG_WIFI_MULTI("[WIFI] SSID: %s\n", WiFi.SSID()); DEBUG_WIFI_MULTI("[WIFI] IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); + DEBUG_WIFI_MULTI("[WIFI] MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + DEBUG_WIFI_MULTI("[WIFI] Channel: %d\n", WiFi.Channel()); break; case WL_NO_SSID_AVAIL: DEBUG_WIFI_MULTI("[WIFI] Connecting Faild AP not found.\n"); From 6b05ec5b8673fbb4626f50f88806eb447455344d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 02:20:41 +0300 Subject: [PATCH 2/8] Update readme and change log #295 #299 --- README.md | 12 ++++++++---- changes.md | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0ae241a91..a6f2dca83 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ GPIO16 can be ```INPUT```, ```OUTPUT``` or ```INPUT_PULLDOWN```. ```analogRead(A0)``` reads the value of the ADC channel connected to the TOUT pin. ```analogWrite(pin, value)``` enables software PWM on the given pin. PWM may be used on pins 0 to 15. -Call ```analogWrite(pin, 0)``` to disable PWM on the pin. +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. Pin interrupts are supported through ```attachInterrupt```, ```detachInterrupt``` functions. Interrupts may be attached to any GPIO pin, except GPIO16. Standard Arduino interrupt @@ -85,7 +85,7 @@ Both ```Serial``` and ```Serial1``` objects support 5, 6, 7, 8 data bits, odd (O #### Progmem #### 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. -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. +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. #### WiFi(ESP8266WiFi library) #### @@ -171,8 +171,8 @@ Several APIs may be used to get flash chip info: #### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) #### Library was adapted to work with ESP8266 by including register definitions into OneWire.h -Note that if you have OneWire library in your Arduino/libraries folder, it will be used -instead of the one that comes with the Arduino IDE (this one). +Note that if you already have OneWire library in your Arduino/libraries folder, it will be used +instead of the one that comes with this package. #### mDNS responder (ESP8266mDNS library) #### @@ -253,3 +253,7 @@ Espressif SDK included in this build is under Espressif Public License. Esptool written by Christian Klippel is licensed under GPLv2, currently maintained by Ivan Grokhotkov: https://github.com/igrr/esptool-ck. ESP8266 core support, ESP8266WiFi, Ticker, ESP8266WebServer libraries were written by Ivan Grokhotkov, ivan@esp8266.com. + +[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. + + diff --git a/changes.md b/changes.md index 25c27a12f..ef8a331f4 100644 --- a/changes.md +++ b/changes.md @@ -1,21 +1,28 @@ +# Change log +## Current version -# Current version +### Tools + +- Add 32-bit Linux toolchain. +- Rebuild toolchain and esptool with support for OS X down to 10.6. + +### Libraries -- Add 32-bit Linux toolchain - Better connection handling in ESP8266WebServer. The server now sends Content-Length and Connection: close headers, then waits for the client to disconnect. By not closing the connection - actively, server avoids TIME_WAIT TCP state, and the TCP stack is able to + actively, server avoids TIME_WAIT TCP state, and TCP stack is able to release the memory immediately, without waiting for 2xMSL period. If the client doesn't disconnect in 2000ms, the server closes the connection actively. - Add Hash library, which has a function to calculate SHA1 hash. + --- -# 1.6.4-g545ffde -19 May, 2015 +## 1.6.4-g545ffde +May 19, 2015 -- Initial release of board manager package +- Initial release of Boards Manager package for ESP8266 platform. From ebc25a43cd6a608f20f26a386e08a0a3c3c66622 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 03:03:17 +0300 Subject: [PATCH 3/8] Update change log --- changes.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/changes.md b/changes.md index ef8a331f4..afaa2a9b1 100644 --- a/changes.md +++ b/changes.md @@ -1,6 +1,7 @@ # Change log -## Current version +## 1.6.4-673-g8cd3697 +May 22, 2015 ### Tools @@ -17,11 +18,12 @@ If the client doesn't disconnect in 2000ms, the server closes the connection actively. - Add Hash library, which has a function to calculate SHA1 hash. - +- SD, Adafruit_ILI9341, and OneWire libraries are now bundled. +- Fix incorrect sector calculation in EEPROM library. --- -## 1.6.4-g545ffde +## 1.6.4-628-g545ffde May 19, 2015 - Initial release of Boards Manager package for ESP8266 platform. From 38ff6296225c55fe9a5995fd52d821ff4d313efb Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 03:07:06 +0300 Subject: [PATCH 4/8] Update README.md add link to change log [ci skip] --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a6f2dca83..8dbc20d13 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package - Enter ```http://arduino.esp8266.com/package_esp8266com_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas. - 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). +### [Change log](hardware/esp8266com/esp8266/changes.md) + ### Building latest version from source ### ``` $ git clone https://github.com/esp8266/Arduino.git From 84679db2dc2fce00dc5e1449319027c89f12e2ee Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 03:12:22 +0300 Subject: [PATCH 5/8] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add donation link — donations are collected towards the esp8266 community forum. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8dbc20d13..80365fe69 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Arduino-compatible IDE with ESP8266 support =========================================== ![Linux build status](http://img.shields.io/travis/igrr/Arduino.svg) +[![Donate](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/webscr?cmd=_s-xclick&hosted_button_id=4M56YCWV6PX66) 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. From 5bdb26ac29a4d116c1c4920ef110b9d2771650da Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 03:36:04 +0300 Subject: [PATCH 6/8] code review --- libraries/ESP8266WiFi/src/ESP8266WiFi.cpp | 24 +++++++++---------- libraries/ESP8266WiFi/src/ESP8266WiFi.h | 6 ++--- .../ESP8266WiFi/src/ESP8266WiFiMulti.cpp | 8 +++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp index 372df9ed0..1ec6f8b36 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp @@ -38,9 +38,9 @@ extern "C" void esp_schedule(); extern "C" void esp_yield(); ESP8266WiFiClass::ESP8266WiFiClass() +: _useApMode(false) +, _useClientMode(false) { - useApMode = false; - useClientMode = false; } void ESP8266WiFiClass::mode(WiFiMode m) @@ -55,9 +55,9 @@ int ESP8266WiFiClass::begin(char* ssid, char *passphrase, int32_t channel, uint8 } int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){ - useClientMode = true; + _useClientMode = true; - if(useApMode) { + if(_useApMode) { // turn on AP+STA mode mode(WIFI_AP_STA); } else { @@ -143,7 +143,7 @@ void ESP8266WiFiClass::softAP(const char* ssid) void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel) { - if(useClientMode) { + if(_useClientMode) { // turn on AP+STA mode mode(WIFI_AP_STA); } else { @@ -371,18 +371,18 @@ bool ESP8266WiFiClass::isHidden(uint8_t i) return (it->is_hidden != 0); } -bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, const char** ssid, uint8_t * encType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden) +bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel, bool &isHidden) { struct bss_info* it = reinterpret_cast(_getScanInfoByIndex(i)); if (!it) return false; - *ssid = (const char*) &it->ssid[0]; // move ptr - *encType = encryptionType(i); - *RSSI = it->rssi; - *BSSID = &it->bssid[0]; // move ptr - *channel = it->channel; - *isHidden = (it->is_hidden != 0); + ssid = (const char*)it->ssid; + encType = encryptionType(i); + rssi = it->rssi; + bssid = it->bssid; // move ptr + channel = it->channel; + isHidden = (it->is_hidden != 0); return true; } diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/libraries/ESP8266WiFi/src/ESP8266WiFi.h index caefbc7df..f1a2977c3 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -238,7 +238,7 @@ public: * @param isHidden bool * * @return (true if ok) */ - bool getNetworkInfo(uint8_t networkItem, const char** ssid, uint8_t * encryptionType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden); + bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden); /* @@ -290,8 +290,8 @@ protected: static void _smartConfigDone(void* result); bool _smartConfigStarted = false; - bool useApMode; - bool useClientMode; + bool _useApMode; + bool _useClientMode; static size_t _scanCount; static void* _scanResult; diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp index de14a0cb5..7aab82ae0 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp @@ -59,21 +59,21 @@ wl_status_t ESP8266WiFiMulti::run(void) { DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", n); for(int8_t i = 0; i < n; ++i) { - const char * ssid_scan; + String ssid_scan; int32_t rssi_scan; uint8_t sec_scan; - uint8_t * BSSID_scan; + uint8_t* BSSID_scan; int32_t chan_scan; bool hidden_scan; - WiFi.getNetworkInfo(i, &ssid_scan, &sec_scan, &rssi_scan, &BSSID_scan, &chan_scan, &hidden_scan); + WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan); bool known = false; for(uint32_t x = 0; x < APlist.size(); x++) { WifiAPlist_t entry = APlist[x]; - if(strcmp(entry.ssid, ssid_scan) == 0) { // SSID match + if(ssid_scan == entry.ssid) { // SSID match known = true; if(rssi_scan > bestNetworkDb) { // best network if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan From d30e1181cfeb510257c129b8ec3d1c3bf215ec4a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 03:49:10 +0300 Subject: [PATCH 7/8] Update README.md mention Blynk [ci skip] --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 80365fe69..65ed84f9d 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,7 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266. +- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)). #### Upload via serial port #### Pick the correct serial port. From b493f01b394581a70be50e230e9e91ce243d7cd1 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 May 2015 14:56:39 +0300 Subject: [PATCH 8/8] Update README.md Mention the new pubsubclient library. [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 65ed84f9d..373b645a4 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ See attached example and library README file for details. 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: - [aREST](https://github.com/marcoschwartz/aREST) REST API handler library. -- [PubSubClient](https://github.com/knolleary/pubsubclient) MQTT library. Use this [sample](https://gist.github.com/igrr/7f7e7973366fc01d6393) to get started. +- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. - [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);``` - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.