Browse Source

Support for Smart Config via JustWifi

fastled^2
Xose Pérez 6 years ago
parent
commit
81eb809d4f
6 changed files with 60 additions and 20 deletions
  1. +6
    -3
      code/espurna/button.ino
  2. +1
    -1
      code/espurna/config/defaults.h
  3. +8
    -6
      code/espurna/config/types.h
  4. +3
    -3
      code/espurna/led.ino
  5. +41
    -6
      code/espurna/wifi.ino
  6. +1
    -1
      code/platformio.ini

+ 6
- 3
code/espurna/button.ino View File

@ -117,9 +117,12 @@ void buttonEvent(unsigned int id, unsigned char event) {
}
}
if (action == BUTTON_MODE_AP) wifiStartAP();
#if !defined(JUSTWIFI_DISABLE_WPS)
if (action == BUTTON_MODE_WPS) wifiStartWPS();
#endif
#if defined(JUSTWIFI_ENABLE_WPS)
if (action == BUTTON_MODE_WPS) wifiStartWPS();
#endif // defined(JUSTWIFI_ENABLE_WPS)
#if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
if (action == BUTTON_MODE_SMART_CONFIG) wifiStartSmartConfig();
#endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
if (action == BUTTON_MODE_RESET) {
deferredReset(100, CUSTOM_RESET_HARDWARE);
}


+ 1
- 1
code/espurna/config/defaults.h View File

@ -109,7 +109,7 @@
#endif
#ifndef BUTTON1_TRIPLECLICK
#define BUTTON1_TRIPLECLICK BUTTON_MODE_WPS
#define BUTTON1_TRIPLECLICK BUTTON_MODE_SMART_CONFIG
#endif
#ifndef BUTTON2_TRIPLECLICK
#define BUTTON2_TRIPLECLICK BUTTON_MODE_NONE


+ 8
- 6
code/espurna/config/types.h View File

@ -7,13 +7,14 @@
// WIFI
// -----------------------------------------------------------------------------
#define WIFI_STATE_AP 1
#define WIFI_STATE_STA 2
#define WIFI_STATE_AP_STA 3
#define WIFI_STATE_WPS 4
#define WIFI_STATE_AP 1
#define WIFI_STATE_STA 2
#define WIFI_STATE_AP_STA 3
#define WIFI_STATE_WPS 4
#define WIFI_STATE_SMARTCONFIG 8
#define WIFI_AP_ALLWAYS 1
#define WIFI_AP_FALLBACK 2
#define WIFI_AP_ALLWAYS 1
#define WIFI_AP_FALLBACK 2
//------------------------------------------------------------------------------
// BUTTONS
@ -37,6 +38,7 @@
#define BUTTON_MODE_PULSE 6
#define BUTTON_MODE_FACTORY 7
#define BUTTON_MODE_WPS 8
#define BUTTON_MODE_SMART_CONFIG 9
// Needed for ESP8285 boards under Windows using PlatformIO (?)
#ifndef BUTTON_PUSHBUTTON


+ 3
- 3
code/espurna/led.ino View File

@ -188,7 +188,7 @@ void ledLoop() {
if (_ledMode(i) == LED_MODE_WIFI) {
if (wifi_state & WIFI_STATE_WPS) {
if (wifi_state & WIFI_STATE_WPS || wifi_state & WIFI_STATE_SMARTCONFIG) {
_ledBlink(i, 100, 100);
} else if (wifi_state & WIFI_STATE_STA) {
_ledBlink(i, 4900, 100);
@ -202,7 +202,7 @@ void ledLoop() {
if (_ledMode(i) == LED_MODE_FINDME_WIFI) {
if (wifi_state & WIFI_STATE_WPS) {
if (wifi_state & WIFI_STATE_WPS || wifi_state & WIFI_STATE_SMARTCONFIG) {
_ledBlink(i, 100, 100);
} else if (wifi_state & WIFI_STATE_STA) {
if (relayStatus(_leds[i].relay-1)) {
@ -224,7 +224,7 @@ void ledLoop() {
if (_ledMode(i) == LED_MODE_RELAY_WIFI) {
if (wifi_state & WIFI_STATE_WPS) {
if (wifi_state & WIFI_STATE_WPS || wifi_state & WIFI_STATE_SMARTCONFIG) {
_ledBlink(i, 100, 100);
} else if (wifi_state & WIFI_STATE_STA) {
if (relayStatus(_leds[i].relay-1)) {


+ 41
- 6
code/espurna/wifi.ino View File

@ -11,6 +11,7 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
uint32_t _wifi_scan_client_id = 0;
bool _wifi_wps_running = false;
bool _wifi_smartconfig_running = false;
uint8_t _wifi_ap_mode = WIFI_AP_FALLBACK;
// -----------------------------------------------------------------------------
@ -218,11 +219,16 @@ void _wifiCallback(justwifi_messages_t code, char * parameter) {
_wifi_wps_running = true;
}
if (MESSAGE_WPS_ERROR == code) {
if (MESSAGE_SMARTCONFIG_START == code) {
_wifi_smartconfig_running = true;
}
if (MESSAGE_WPS_ERROR == code || MESSAGE_SMARTCONFIG_ERROR == code) {
_wifi_wps_running = false;
_wifi_smartconfig_running = false;
}
if (MESSAGE_WPS_SUCCESS == code) {
if (MESSAGE_WPS_SUCCESS == code || MESSAGE_SMARTCONFIG_SUCCESS == code) {
String ssid = WiFi.SSID();
String pass = WiFi.psk();
@ -242,6 +248,7 @@ void _wifiCallback(justwifi_messages_t code, char * parameter) {
setSetting("pass", count, pass);
_wifi_wps_running = false;
_wifi_smartconfig_running = false;
}
@ -350,6 +357,20 @@ void _wifiDebugCallback(justwifi_messages_t code, char * parameter) {
DEBUG_MSG_P(PSTR("[WIFI] WPS failed\n"));
}
// ------------------------------------------------------------------------
if (code == MESSAGE_SMARTCONFIG_START) {
DEBUG_MSG_P(PSTR("[WIFI] Smart Config started\n"));
}
if (code == MESSAGE_SMARTCONFIG_SUCCESS) {
DEBUG_MSG_P(PSTR("[WIFI] Smart Config succeded!\n"));
}
if (code == MESSAGE_SMARTCONFIG_ERROR) {
DEBUG_MSG_P(PSTR("[WIFI] Smart Config failed\n"));
}
}
#endif // DEBUG_SUPPORT
@ -373,12 +394,19 @@ void _wifiInitCommands() {
DEBUG_MSG_P(PSTR("+OK\n"));
});
#if !defined(JUSTWIFI_DISABLE_WPS)
#if defined(JUSTWIFI_ENABLE_WPS)
settingsRegisterCommand(F("WIFI.WPS"), [](Embedis* e) {
wifiStartWPS();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
#endif // defined(JUSTWIFI_ENABLE_WPS)
#if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
settingsRegisterCommand(F("WIFI.SMARTCONFIG"), [](Embedis* e) {
wifiStartSmartConfig();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
settingsRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) {
_wifiScan();
@ -520,11 +548,17 @@ void wifiStartAP() {
wifiStartAP(true);
}
#if !defined(JUSTWIFI_DISABLE_WPS)
#if defined(JUSTWIFI_ENABLE_WPS)
void wifiStartWPS() {
jw.startWPS();
}
#endif
#endif // defined(JUSTWIFI_ENABLE_WPS)
#if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
void wifiStartSmartConfig() {
jw.startSmartConfig();
}
#endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
void wifiReconnectCheck() {
bool connected = false;
@ -542,6 +576,7 @@ uint8_t wifiState() {
if (jw.connected()) state += WIFI_STATE_STA;
if (jw.connectable()) state += WIFI_STATE_AP;
if (_wifi_wps_running) state += WIFI_STATE_WPS;
if (_wifi_smartconfig_running) state += WIFI_STATE_SMARTCONFIG;
return state;
}


+ 1
- 1
code/platformio.ini View File

@ -35,7 +35,7 @@ debug_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY v2 Lower Memory
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH v2 Higher Bandwidth
# ------------------------------------------------------------------------------
build_flags = -g -DMQTT_MAX_PACKET_SIZE=400 ${env.ESPURNA_FLAGS} -DJUSTWIFI_DISABLE_WPS -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
build_flags = -g -DMQTT_MAX_PACKET_SIZE=400 -DJUSTWIFI_ENABLE_SMARTCONFIG ${env.ESPURNA_FLAGS} -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
build_flags_512k = ${common.build_flags} -Wl,-Tesp8266.flash.512k0.ld
build_flags_1m = ${common.build_flags} -Wl,-Tesp8266.flash.1m0.ld


Loading…
Cancel
Save