diff --git a/platformio.ini b/platformio.ini index 1069f8e0..0ba38adc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -160,7 +160,7 @@ build_flags = -Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.3 ;-DCFG_DEBUG=3 src_filter = - ${env.src_filter} - - + ${env.src_filter} - - - lib_ignore = BluetoothOTA monitor_port = /dev/ttyACM1 diff --git a/src/configuration.h b/src/configuration.h index e70f1fda..b9c86910 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -101,6 +101,8 @@ along with this program. If not, see . // Standard definitions for ESP32 targets // +#define HAS_WIFI + #define GPS_SERIAL_NUM 1 #define GPS_RX_PIN 34 #ifdef USE_JTAG diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 29637934..6675d8a1 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -32,7 +32,6 @@ along with this program. If not, see . #include "main.h" #include "mesh-pb-constants.h" #include "utils.h" -#include #include "meshwifi/meshwifi.h" using namespace meshtastic; /** @todo remove */ @@ -842,6 +841,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 // Jm void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { +#ifdef HAS_WIFI const char *wifiName = radioConfig.preferences.wifi_ssid; const char *wifiPsw = radioConfig.preferences.wifi_password; @@ -869,6 +869,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i display->setPixel(0, 0); heartbeat = !heartbeat; #endif +#endif } diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 8f5a6de2..0fc6e588 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -17,7 +17,6 @@ #include "concurrency/PeriodicTask.h" #include "power.h" #include -#include namespace graphics { diff --git a/src/meshwifi/meshhttp.h b/src/meshwifi/meshhttp.h index cbff51db..cabb1a2c 100644 --- a/src/meshwifi/meshhttp.h +++ b/src/meshwifi/meshhttp.h @@ -2,7 +2,6 @@ #include #include -#include void initWebServer(); diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 14ac8a2a..8c1d2c8f 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -1,11 +1,13 @@ #include "meshwifi.h" -#include +#include "NodeDB.h" #include "configuration.h" #include "main.h" -#include "NodeDB.h" #include "meshwifi/meshhttp.h" +#include -bool isWifiAvailable() +static void WiFiEvent(WiFiEvent_t event); + +bool isWifiAvailable() { const char *wifiName = radioConfig.preferences.wifi_ssid; const char *wifiPsw = radioConfig.preferences.wifi_password; @@ -20,33 +22,31 @@ bool isWifiAvailable() // Disable WiFi void deinitWifi() { - /* + /* Note from Jm (Sept 16, 2020): - + A bug in the ESP32 SDK was introduced in Oct 2019 that keeps the WiFi radio from turning back on after it's shut off. See: https://github.com/espressif/arduino-esp32/issues/3522 Until then, WiFi should only be allowed when there's no power saving on the 2.4g transceiver. - */ + */ WiFi.mode(WIFI_MODE_NULL); DEBUG_MSG("WiFi Turned Off\n"); WiFi.printDiag(Serial); } - // Startup WiFi void initWifi() { - if (isWifiAvailable() == 0) { return; } - //strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); - //strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD); + // strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); + // strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD); if (radioConfig.has_preferences) { const char *wifiName = radioConfig.preferences.wifi_ssid; @@ -57,8 +57,7 @@ void initWifi() } else { WiFi.mode(WIFI_MODE_STA); WiFi.onEvent(WiFiEvent); - //esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving - + // esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving DEBUG_MSG("JOINING WIFI: ssid=%s\n", wifiName); if (WiFi.begin(wifiName, wifiPsw) == WL_CONNECTED) { @@ -72,95 +71,95 @@ void initWifi() DEBUG_MSG("Not using WIFI\n"); } - -void WiFiEvent(WiFiEvent_t event) +static void WiFiEvent(WiFiEvent_t event) { DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event); switch (event) { - case SYSTEM_EVENT_WIFI_READY: - DEBUG_MSG("WiFi interface ready\n"); - break; - case SYSTEM_EVENT_SCAN_DONE: - DEBUG_MSG("Completed scan for access points\n"); - break; - case SYSTEM_EVENT_STA_START: - DEBUG_MSG("WiFi client started\n"); - break; - case SYSTEM_EVENT_STA_STOP: - DEBUG_MSG("WiFi clients stopped\n"); - break; - case SYSTEM_EVENT_STA_CONNECTED: - DEBUG_MSG("Connected to access point\n"); - break; - case SYSTEM_EVENT_STA_DISCONNECTED: - DEBUG_MSG("Disconnected from WiFi access point\n"); + case SYSTEM_EVENT_WIFI_READY: + DEBUG_MSG("WiFi interface ready\n"); + break; + case SYSTEM_EVENT_SCAN_DONE: + DEBUG_MSG("Completed scan for access points\n"); + break; + case SYSTEM_EVENT_STA_START: + DEBUG_MSG("WiFi client started\n"); + break; + case SYSTEM_EVENT_STA_STOP: + DEBUG_MSG("WiFi clients stopped\n"); + break; + case SYSTEM_EVENT_STA_CONNECTED: + DEBUG_MSG("Connected to access point\n"); + break; + case SYSTEM_EVENT_STA_DISCONNECTED: + DEBUG_MSG("Disconnected from WiFi access point\n"); - // Reconnect WiFi - initWifi(); - break; - case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: - DEBUG_MSG("Authentication mode of access point has changed\n"); - break; - case SYSTEM_EVENT_STA_GOT_IP: - DEBUG_MSG("Obtained IP address: \n"); - Serial.println(WiFi.localIP()); + // Reconnect WiFi + initWifi(); + break; + case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: + DEBUG_MSG("Authentication mode of access point has changed\n"); + break; + case SYSTEM_EVENT_STA_GOT_IP: + DEBUG_MSG("Obtained IP address: \n"); + Serial.println(WiFi.localIP()); - // Start web server - initWebServer(); - - break; - case SYSTEM_EVENT_STA_LOST_IP: - DEBUG_MSG("Lost IP address and IP address is reset to 0\n"); - break; - case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: - DEBUG_MSG("WiFi Protected Setup (WPS): succeeded in enrollee mode\n"); - break; - case SYSTEM_EVENT_STA_WPS_ER_FAILED: - DEBUG_MSG("WiFi Protected Setup (WPS): failed in enrollee mode\n"); - break; - case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: - DEBUG_MSG("WiFi Protected Setup (WPS): timeout in enrollee mode\n"); - break; - case SYSTEM_EVENT_STA_WPS_ER_PIN: - DEBUG_MSG("WiFi Protected Setup (WPS): pin code in enrollee mode\n"); - break; - case SYSTEM_EVENT_AP_START: - DEBUG_MSG("WiFi access point started\n"); - break; - case SYSTEM_EVENT_AP_STOP: - DEBUG_MSG("WiFi access point stopped\n"); - break; - case SYSTEM_EVENT_AP_STACONNECTED: - DEBUG_MSG("Client connected\n"); - break; - case SYSTEM_EVENT_AP_STADISCONNECTED: - DEBUG_MSG("Client disconnected\n"); - break; - case SYSTEM_EVENT_AP_STAIPASSIGNED: - DEBUG_MSG("Assigned IP address to client\n"); - break; - case SYSTEM_EVENT_AP_PROBEREQRECVED: - DEBUG_MSG("Received probe request\n"); - break; - case SYSTEM_EVENT_GOT_IP6: - DEBUG_MSG("IPv6 is preferred\n"); - break; - case SYSTEM_EVENT_ETH_START: - DEBUG_MSG("Ethernet started\n"); - break; - case SYSTEM_EVENT_ETH_STOP: - DEBUG_MSG("Ethernet stopped\n"); - break; - case SYSTEM_EVENT_ETH_CONNECTED: - DEBUG_MSG("Ethernet connected\n"); - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - DEBUG_MSG("Ethernet disconnected\n"); - break; - case SYSTEM_EVENT_ETH_GOT_IP: - DEBUG_MSG("Obtained IP address\n"); - break; - default: break; + // Start web server + initWebServer(); + + break; + case SYSTEM_EVENT_STA_LOST_IP: + DEBUG_MSG("Lost IP address and IP address is reset to 0\n"); + break; + case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: + DEBUG_MSG("WiFi Protected Setup (WPS): succeeded in enrollee mode\n"); + break; + case SYSTEM_EVENT_STA_WPS_ER_FAILED: + DEBUG_MSG("WiFi Protected Setup (WPS): failed in enrollee mode\n"); + break; + case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: + DEBUG_MSG("WiFi Protected Setup (WPS): timeout in enrollee mode\n"); + break; + case SYSTEM_EVENT_STA_WPS_ER_PIN: + DEBUG_MSG("WiFi Protected Setup (WPS): pin code in enrollee mode\n"); + break; + case SYSTEM_EVENT_AP_START: + DEBUG_MSG("WiFi access point started\n"); + break; + case SYSTEM_EVENT_AP_STOP: + DEBUG_MSG("WiFi access point stopped\n"); + break; + case SYSTEM_EVENT_AP_STACONNECTED: + DEBUG_MSG("Client connected\n"); + break; + case SYSTEM_EVENT_AP_STADISCONNECTED: + DEBUG_MSG("Client disconnected\n"); + break; + case SYSTEM_EVENT_AP_STAIPASSIGNED: + DEBUG_MSG("Assigned IP address to client\n"); + break; + case SYSTEM_EVENT_AP_PROBEREQRECVED: + DEBUG_MSG("Received probe request\n"); + break; + case SYSTEM_EVENT_GOT_IP6: + DEBUG_MSG("IPv6 is preferred\n"); + break; + case SYSTEM_EVENT_ETH_START: + DEBUG_MSG("Ethernet started\n"); + break; + case SYSTEM_EVENT_ETH_STOP: + DEBUG_MSG("Ethernet stopped\n"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + DEBUG_MSG("Ethernet connected\n"); + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + DEBUG_MSG("Ethernet disconnected\n"); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + DEBUG_MSG("Obtained IP address\n"); + break; + default: + break; } } \ No newline at end of file diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index 044839ab..9f018de0 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -1,13 +1,15 @@ #pragma once +#include "configuration.h" #include #include + +#ifdef HAS_WIFI #include +#endif void initWifi(); void deinitWifi(); -void WiFiEvent(WiFiEvent_t event); - bool isWifiAvailable(); \ No newline at end of file diff --git a/src/nrf52/wifi-nrf52.cpp b/src/nrf52/wifi-nrf52.cpp new file mode 100644 index 00000000..e4885add --- /dev/null +++ b/src/nrf52/wifi-nrf52.cpp @@ -0,0 +1,13 @@ +#include "meshwifi/meshhttp.h" +#include "meshwifi/meshwifi.h" + +void initWifi() {} + +void deinitWifi() {} + +bool isWifiAvailable() +{ + return false; +} + +void handleWebResponse() {} \ No newline at end of file