diff --git a/README.md b/README.md index 4732fbda..fa37e576 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.12.6-brightgreen.svg)](CHANGELOG.md) -[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.org/xoseperez/espurna/tree/dev/) -[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) -[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) +[![branch](https://img.shields.io/badge/branch-justwifi2-orange.svg)](https://github.org/xoseperez/espurna/tree/justwifi2/) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=justwifi2)](https://travis-ci.org/xoseperez/espurna) +[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/justwifi2.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 245792aa..f8e9a7b9 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -276,9 +276,6 @@ #define WIFI_AP_CAPTIVE 1 // Captive portal enabled when in AP mode #endif -#ifndef WIFI_AP_MODE -#define WIFI_AP_MODE AP_MODE_ALONE -#endif #ifndef WIFI_SLEEP_MODE #define WIFI_SLEEP_MODE WIFI_NONE_SLEEP // WIFI_NONE_SLEEP, WIFI_LIGHT_SLEEP or WIFI_MODEM_SLEEP @@ -1148,13 +1145,13 @@ #if IR_BUTTON_SET == 3 /* +------+------+------+ - | 1 | 2 | 3 | + | 1 | 2 | 3 | +------+------+------+ - | 4 | 5 | 6 | + | 4 | 5 | 6 | +------+------+------+ - | 7 | 8 | 9 | + | 7 | 8 | 9 | +------+------+------+ - | | 0 | | + | | 0 | | +------+------+------+ */ #define IR_BUTTON_COUNT 10 @@ -1164,7 +1161,7 @@ { 0xE0E020DF, IR_BUTTON_MODE_TOGGLE, 0 }, // Toggle Relay #0 { 0xE0E0A05F, IR_BUTTON_MODE_TOGGLE, 1 }, // Toggle Relay #1 { 0xE0E0609F, IR_BUTTON_MODE_TOGGLE, 2 }, // Toggle Relay #2 - + { 0xE0E010EF, IR_BUTTON_MODE_TOGGLE, 3 }, // Toggle Relay #3 { 0xE0E0906F, IR_BUTTON_MODE_TOGGLE, 4 }, // Toggle Relay #4 { 0xE0E050AF, IR_BUTTON_MODE_TOGGLE, 5 }, // Toggle Relay #5 diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index 8fc2e23f..4e8c00af 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -25,7 +25,7 @@ void _wifiConfigure() { #endif jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT); wifiReconnectCheck(); - jw.setAPMode(WIFI_AP_MODE); + jw.enableAPFailsafe(true); jw.cleanNetworks(); // If system is flagged unstable we do not init wifi networks @@ -196,6 +196,31 @@ void _wifiInject() { } } +void _wifiWPS(justwifi_messages_t code, char * parameter) { + + if (MESSAGE_WPS_SUCCESS == code) { + + String ssid = WiFi.SSID(); + String pass = WiFi.psk(); + + // Look for the same SSID + uint8_t count = 0; + while (count < WIFI_MAX_NETWORKS) { + if (!hasSetting("ssid", count)) break; + if (getSetting("ssid", count).equals(ssid)) break; + count++; + } + + // If we have reached the max we overwrite the first one + if (WIFI_MAX_NETWORKS == count) count = 0; + + setSetting("ssid", count, ssid); + setSetting("pass", count, pass); + + } + +} + #if WIFI_AP_CAPTIVE #include "DNSServer.h" @@ -223,6 +248,8 @@ void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) { void _wifiDebug(justwifi_messages_t code, char * parameter) { + // ------------------------------------------------------------------------- + if (code == MESSAGE_SCANNING) { DEBUG_MSG_P(PSTR("[WIFI] Scanning\n")); } @@ -243,6 +270,8 @@ void _wifiDebug(justwifi_messages_t code, char * parameter) { DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter); } + // ------------------------------------------------------------------------- + if (code == MESSAGE_CONNECTING) { DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter); } @@ -259,22 +288,38 @@ void _wifiDebug(justwifi_messages_t code, char * parameter) { wifiStatus(); } - if (code == MESSAGE_ACCESSPOINT_CREATED) { - wifiStatus(); - } - if (code == MESSAGE_DISCONNECTED) { DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n")); } + // ------------------------------------------------------------------------- + if (code == MESSAGE_ACCESSPOINT_CREATING) { DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n")); } + if (code == MESSAGE_ACCESSPOINT_CREATED) { + wifiStatus(); + } + if (code == MESSAGE_ACCESSPOINT_FAILED) { DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n")); } + // ------------------------------------------------------------------------- + + if (code == MESSAGE_WPS_START) { + DEBUG_MSG_P(PSTR("[WIFI] WPS started\n")); + } + + if (code == MESSAGE_WPS_SUCCESS) { + DEBUG_MSG_P(PSTR("[WIFI] WPS succeded!\n")); + } + + if (code == MESSAGE_WPS_ERROR) { + DEBUG_MSG_P(PSTR("[WIFI] WPS failed\n")); + } + } #endif // DEBUG_SUPPORT @@ -298,6 +343,11 @@ void _wifiInitCommands() { DEBUG_MSG_P(PSTR("+OK\n")); }); + settingsRegisterCommand(F("WIFI.WPS"), [](Embedis* e) { + jw.startWPS(); + DEBUG_MSG_P(PSTR("+OK\n")); + }); + settingsRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) { _wifiScan(); DEBUG_MSG_P(PSTR("+OK\n")); @@ -445,6 +495,7 @@ void wifiSetup() { _wifiConfigure(); // Message callbacks + wifiRegister(_wifiWPS); #if WIFI_AP_CAPTIVE wifiRegister(_wifiCaptivePortal); #endif diff --git a/code/platformio.ini b/code/platformio.ini index 384223a2..c9efef0f 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -64,7 +64,7 @@ lib_deps = https://bitbucket.org/xoseperez/fauxmoesp.git#2.4.2 https://github.com/xoseperez/hlw8012.git#1.1.0 https://github.com/markszabo/IRremoteESP8266#v2.2.0 - https://github.com/xoseperez/justwifi.git#1.2.0 + https://github.com/xoseperez/justwifi.git#v2 https://github.com/madpilot/mDNSResolver#4cfcda1 https://github.com/xoseperez/my92xx#3.0.1 https://bitbucket.org/xoseperez/nofuss.git#0.2.5