From 5d0d64d447728338c37f077922e11447acf893c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 10 Jan 2018 19:25:53 +0100 Subject: [PATCH] Update JustWifi library to 1.1.6 --- code/espurna/config/prototypes.h | 7 ++ code/espurna/mdns.ino | 21 +++-- code/espurna/wifi.ino | 141 ++++++++++++++++--------------- code/platformio.ini | 2 +- 4 files changed, 95 insertions(+), 76 deletions(-) diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index 2239c523..145f324f 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -33,6 +33,13 @@ void wsOnActionRegister(ws_on_action_callback_f callback); typedef std::function ws_on_after_parse_callback_f; void wsOnAfterParseRegister(ws_on_after_parse_callback_f callback); +// ----------------------------------------------------------------------------- +// WIFI +// ----------------------------------------------------------------------------- +#include "JustWifi.h" +typedef std::function wifi_callback_f; +void wifiRegister(wifi_callback_f callback); + // ----------------------------------------------------------------------------- // MQTT // ----------------------------------------------------------------------------- diff --git a/code/espurna/mdns.ino b/code/espurna/mdns.ino index 018c2e38..69db986a 100644 --- a/code/espurna/mdns.ino +++ b/code/espurna/mdns.ino @@ -10,9 +10,6 @@ Copyright (C) 2017-2018 by Xose PĂ©rez #include -WiFiEventHandler _mdns_wifi_onSTA; -WiFiEventHandler _mdns_wifi_onAP; - #if MQTT_SUPPORT void mdnsFindMQTT() { int count = MDNS.queryService("mqtt", "tcp"); @@ -62,11 +59,19 @@ void mdnsSetup() { MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *) buffer); } - _mdns_wifi_onSTA = WiFi.onStationModeGotIP([](WiFiEventStationModeGotIP ipInfo) { - _mdnsStart(); - }); - _mdns_wifi_onAP = WiFi.onSoftAPModeStationConnected([](WiFiEventSoftAPModeStationConnected ipInfo) { - _mdnsStart(); + wifiRegister([](justwifi_messages_t code, char * parameter) { + + if (code == MESSAGE_CONNECTED) { + _mdnsStart(); + #if MQTT_SUPPORT + mdnsFindMQTT(); + #endif // MQTT_SUPPORT + } + + if (code == MESSAGE_ACCESSPOINT_CREATED) { + _mdnsStart(); + } + }); } diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index 7232bf71..a706cd60 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -129,21 +129,26 @@ void wifiStatus() { } if ((WiFi.getMode() & WIFI_AP) == WIFI_AP) { - DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), jw.getAPSSID().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] PASS %s\n"), getSetting("adminPass", ADMIN_PASS).c_str()); - DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.softAPIP().toString().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.softAPmacAddress().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), jw.getAPSSID().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] PASS %s\n"), getSetting("adminPass", ADMIN_PASS).c_str()); + DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.softAPIP().toString().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.softAPmacAddress().c_str()); } if ((WiFi.getMode() & WIFI_STA) == WIFI_STA) { - DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), WiFi.SSID().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.localIP().toString().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.macAddress().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] GW %s\n"), WiFi.gatewayIP().toString().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] DNS %s\n"), WiFi.dnsIP().toString().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] MASK %s\n"), WiFi.subnetMask().toString().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] HOST %s\n"), WiFi.hostname().c_str()); - DEBUG_MSG_P(PSTR("[WIFI] RSSI %d\n"), WiFi.RSSI()); + uint8_t * bssid = WiFi.BSSID(); + DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), WiFi.SSID().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.localIP().toString().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.macAddress().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] GW %s\n"), WiFi.gatewayIP().toString().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] DNS %s\n"), WiFi.dnsIP().toString().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] MASK %s\n"), WiFi.subnetMask().toString().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] HOST %s\n"), WiFi.hostname().c_str()); + DEBUG_MSG_P(PSTR("[WIFI] BSSID %02X:%02X:%02X:%02X:%02X:%02X\n"), + bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], bssid[6] + ); + DEBUG_MSG_P(PSTR("[WIFI] CH %d\n"), WiFi.channel()); + DEBUG_MSG_P(PSTR("[WIFI] RSSI %d\n"), WiFi.RSSI()); } DEBUG_MSG_P(PSTR("[WIFI] ----------------------------------------------\n")); @@ -276,81 +281,83 @@ void wifiInject() { } -void wifiSetup() { +#if DEBUG_SUPPORT - #if WIFI_SLEEP_ENABLED - wifi_set_sleep_type(LIGHT_SLEEP_T); - #endif +void _wifiDebug(justwifi_messages_t code, char * parameter) { - wifiInject(); - wifiConfigure(); + if (code == MESSAGE_SCANNING) { + DEBUG_MSG_P(PSTR("[WIFI] Scanning\n")); + } - // Message callbacks - jw.onMessage([](justwifi_messages_t code, char * parameter) { + if (code == MESSAGE_SCAN_FAILED) { + DEBUG_MSG_P(PSTR("[WIFI] Scan failed\n")); + } - #if DEBUG_SUPPORT + if (code == MESSAGE_NO_NETWORKS) { + DEBUG_MSG_P(PSTR("[WIFI] No networks found\n")); + } - if (code == MESSAGE_SCANNING) { - DEBUG_MSG_P(PSTR("[WIFI] Scanning\n")); - } + if (code == MESSAGE_NO_KNOWN_NETWORKS) { + DEBUG_MSG_P(PSTR("[WIFI] No known networks found\n")); + } - if (code == MESSAGE_SCAN_FAILED) { - DEBUG_MSG_P(PSTR("[WIFI] Scan failed\n")); - } + if (code == MESSAGE_FOUND_NETWORK) { + DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter); + } - if (code == MESSAGE_NO_NETWORKS) { - DEBUG_MSG_P(PSTR("[WIFI] No networks found\n")); - } + if (code == MESSAGE_CONNECTING) { + DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter); + } - if (code == MESSAGE_NO_KNOWN_NETWORKS) { - DEBUG_MSG_P(PSTR("[WIFI] No known networks found\n")); - } + if (code == MESSAGE_CONNECT_WAITING) { + // too much noise + } - if (code == MESSAGE_FOUND_NETWORK) { - DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter); - } + if (code == MESSAGE_CONNECT_FAILED) { + DEBUG_MSG_P(PSTR("[WIFI] Could not connect to %s\n"), parameter); + } - if (code == MESSAGE_CONNECTING) { - DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter); - } + if (code == MESSAGE_CONNECTED) { + wifiStatus(); + } + + if (code == MESSAGE_ACCESSPOINT_CREATED) { + wifiStatus(); + } - if (code == MESSAGE_CONNECT_WAITING) { - // too much noise - } + if (code == MESSAGE_DISCONNECTED) { + DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n")); + } - if (code == MESSAGE_CONNECT_FAILED) { - DEBUG_MSG_P(PSTR("[WIFI] Could not connect to %s\n"), parameter); - } + if (code == MESSAGE_ACCESSPOINT_CREATING) { + DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n")); + } - if (code == MESSAGE_CONNECTED) { - wifiStatus(); - } + if (code == MESSAGE_ACCESSPOINT_FAILED) { + DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n")); + } - if (code == MESSAGE_ACCESSPOINT_CREATED) { - wifiStatus(); - } +} - if (code == MESSAGE_DISCONNECTED) { - DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n")); - } +#endif // DEBUG_SUPPORT - if (code == MESSAGE_ACCESSPOINT_CREATING) { - DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n")); - } +void wifiRegister(wifi_callback_f callback) { + jw.subscribe(callback); +} - if (code == MESSAGE_ACCESSPOINT_FAILED) { - DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n")); - } +void wifiSetup() { - #endif // DEBUG_SUPPORT + #if WIFI_SLEEP_ENABLED + wifi_set_sleep_type(LIGHT_SLEEP_T); + #endif - #if MQTT_SUPPORT - #if MDNS_SUPPORT - if (code == MESSAGE_CONNECTED) mdnsFindMQTT(); - #endif // MDNS_SUPPORT - #endif // MQTT_SUPPORT + wifiInject(); + wifiConfigure(); - }); + // Message callbacks + #if DEBUG_SUPPORT + wifiRegister(_wifiDebug); + #endif #if WEB_SUPPORT wsOnSendRegister(_wifiWebSocketOnSend); diff --git a/code/platformio.ini b/code/platformio.ini index e90c2308..0ff15986 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -24,7 +24,7 @@ lib_deps = https://github.com/krosk93/espsoftwareserial#a770677 SparkFun BME280 PMS Library - https://bitbucket.org/xoseperez/justwifi.git#1.1.4 + https://bitbucket.org/xoseperez/justwifi.git#1.1.6 https://bitbucket.org/xoseperez/hlw8012.git#1.1.0 https://bitbucket.org/xoseperez/fauxmoesp.git#2.4.0 https://bitbucket.org/xoseperez/nofuss.git#0.2.5