From 209fb585b0acb32f5785f29f84ef3a920ef590f8 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 30 Nov 2023 20:49:00 -0600 Subject: [PATCH 01/11] Default to what G2 comes with --- src/mesh/NodeDB.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 2e6c8131e..262a19263 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -248,6 +248,12 @@ void NodeDB::installDefaultModuleConfig() #ifdef T_WATCH_S3 // Don't worry about the other settings, we'll use the DRV2056 behavior for notifications moduleConfig.external_notification.enabled = true; +#endif +#ifdef NANO_G2_ULTRA + moduleConfig.external_notification.enabled = true; + moduleConfig.external_notification.alert_message = true; + moduleConfig.external_notification.output_ms = 100; + moduleConfig.external_notification.active true; #endif moduleConfig.has_canned_message = true; From a05bab35ad3b163871880c9d3c00dd53b7be8567 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 1 Dec 2023 07:17:38 -0600 Subject: [PATCH 02/11] = --- src/mesh/NodeDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index f2505bb0d..cb5c27b49 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -253,7 +253,7 @@ void NodeDB::installDefaultModuleConfig() moduleConfig.external_notification.enabled = true; moduleConfig.external_notification.alert_message = true; moduleConfig.external_notification.output_ms = 100; - moduleConfig.external_notification.active true; + moduleConfig.external_notification.active = true; #endif moduleConfig.has_canned_message = true; From 4c69d06ac05cd196d939d99d5d2b5444bef435eb Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Sat, 2 Dec 2023 12:30:00 +0000 Subject: [PATCH 03/11] Update Power.cpp (#2979) --- src/Power.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 0a56a1ba2..0fa97b7f0 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -435,7 +435,7 @@ void Power::shutdown() ledOff(PIN_LED2); #endif #ifdef PIN_LED3 - ledOff(PIN_LED2); + ledOff(PIN_LED3); #endif doDeepSleep(DELAY_FOREVER, false); #endif @@ -897,4 +897,4 @@ bool Power::axpChipInit() #else return false; #endif -} \ No newline at end of file +} From 1b6c11c5f1701f8a7cf04daadbfe82b2c386d7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 2 Dec 2023 14:00:20 +0100 Subject: [PATCH 04/11] tryfix crash (#2964) * tryfix crash * only use this when wifi is not enabled. (poking around) --------- Co-authored-by: Ben Meadors --- src/mesh/MeshService.cpp | 4 +++- src/nimble/NimbleBluetooth.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 44094f1bb..4fd9523c0 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -320,7 +320,9 @@ meshtastic_NodeInfoLite *MeshService::refreshLocalMeshNode() position.time = getValidTime(RTCQualityFromNet); - updateBatteryLevel(powerStatus->getBatteryChargePercent()); + if (powerStatus->getHasBattery() == 1) { + updateBatteryLevel(powerStatus->getBatteryChargePercent()); + } return node; } diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 3175e0f09..0b2a806c9 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -186,7 +186,7 @@ void NimbleBluetooth::setupService() // Setup the battery service NimBLEService *batteryService = bleServer->createService(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic) - (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY, 1); NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904); batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8); @@ -208,8 +208,10 @@ void NimbleBluetooth::startAdvertising() /// Given a level between 0-100, update the BLE attribute void updateBatteryLevel(uint8_t level) { - BatteryCharacteristic->setValue(&level, 1); - BatteryCharacteristic->notify(); + if ((config.bluetooth.enabled == true) && bleServer && nimbleBluetooth->isConnected()) { + BatteryCharacteristic->setValue(&level, 1); + BatteryCharacteristic->notify(); + } } void NimbleBluetooth::clearBonds() From 2544733ad40769b8dec528309ae7d3c2459f8c2a Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Sat, 2 Dec 2023 13:40:31 +0000 Subject: [PATCH 05/11] Standardise order for setting GPIO pin default values (#2942) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update SX126xInterface.cpp * Update GPS.cpp * Update TFTDisplay.cpp * Update SX128xInterface.cpp * Update EInkDisplay2.cpp * trunk fmt --------- Co-authored-by: Ben Meadors Co-authored-by: Thomas Göttgens --- src/gps/GPS.cpp | 12 ++++++------ src/graphics/EInkDisplay2.cpp | 6 +++--- src/graphics/TFTDisplay.cpp | 8 ++++---- src/mesh/SX126xInterface.cpp | 2 +- src/mesh/SX128xInterface.cpp | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 7ea36c860..f51fb0588 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -495,14 +495,14 @@ void GPS::setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime) #ifdef PIN_GPS_STANDBY // Specifically the standby pin for L76K and clones if (on) { LOG_INFO("Waking GPS"); - digitalWrite(PIN_GPS_STANDBY, 1); pinMode(PIN_GPS_STANDBY, OUTPUT); + digitalWrite(PIN_GPS_STANDBY, 1); return; } else { LOG_INFO("GPS entering sleep"); // notifyGPSSleep.notifyObservers(NULL); - digitalWrite(PIN_GPS_STANDBY, 0); pinMode(PIN_GPS_STANDBY, OUTPUT); + digitalWrite(PIN_GPS_STANDBY, 0); return; } #endif @@ -920,8 +920,8 @@ GPS *GPS::createGps() if (_en_gpio != 0) { LOG_DEBUG("Setting %d to output.\n", _en_gpio); - digitalWrite(_en_gpio, !GPS_EN_ACTIVE); pinMode(_en_gpio, OUTPUT); + digitalWrite(_en_gpio, !GPS_EN_ACTIVE); } #ifdef PIN_GPS_PPS @@ -941,8 +941,8 @@ GPS *GPS::createGps() new_gps->setGPSPower(true, false, 0); #ifdef PIN_GPS_RESET - digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms pinMode(PIN_GPS_RESET, OUTPUT); + digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms delay(10); digitalWrite(PIN_GPS_RESET, !GPS_RESET_MODE); #endif @@ -987,8 +987,8 @@ bool GPS::factoryReset() { #ifdef PIN_GPS_REINIT // The L76K GNSS on the T-Echo requires the RESET pin to be pulled LOW - digitalWrite(PIN_GPS_REINIT, 0); pinMode(PIN_GPS_REINIT, OUTPUT); + digitalWrite(PIN_GPS_REINIT, 0); delay(150); // The L76K datasheet calls for at least 100MS delay digitalWrite(PIN_GPS_REINIT, 1); #endif @@ -1268,4 +1268,4 @@ int32_t GPS::disable() setAwake(false); return INT32_MAX; -} \ No newline at end of file +} diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index 61d0eea5a..3b97dd723 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -46,7 +46,7 @@ #define TECHO_DISPLAY_MODEL GxEPD2_154_M09 #elif defined(HELTEC_WIRELESS_PAPER) -//#define TECHO_DISPLAY_MODEL GxEPD2_213_T5D +// #define TECHO_DISPLAY_MODEL GxEPD2_213_T5D #define TECHO_DISPLAY_MODEL GxEPD2_213_BN #endif @@ -193,14 +193,14 @@ bool EInkDisplay::connect() LOG_INFO("Doing EInk init\n"); #ifdef PIN_EINK_PWR_ON - digitalWrite(PIN_EINK_PWR_ON, HIGH); // If we need to assert a pin to power external peripherals pinMode(PIN_EINK_PWR_ON, OUTPUT); + digitalWrite(PIN_EINK_PWR_ON, HIGH); // If we need to assert a pin to power external peripherals #endif #ifdef PIN_EINK_EN // backlight power, HIGH is backlight on, LOW is off - digitalWrite(PIN_EINK_EN, LOW); pinMode(PIN_EINK_EN, OUTPUT); + digitalWrite(PIN_EINK_EN, LOW); #endif #if defined(TTGO_T_ECHO) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 63db8120a..618880a5c 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -478,8 +478,8 @@ bool TFTDisplay::connect() LOG_INFO("Doing TFT init\n"); #ifdef TFT_BL - digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); pinMode(TFT_BL, OUTPUT); + digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); // pinMode(PIN_3V3_EN, OUTPUT); // digitalWrite(PIN_3V3_EN, HIGH); LOG_INFO("Power to TFT Backlight\n"); @@ -487,11 +487,11 @@ bool TFTDisplay::connect() #ifdef ST7735_BACKLIGHT_EN_V03 if (heltec_version == 3) { - digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); pinMode(ST7735_BACKLIGHT_EN_V03, OUTPUT); + digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); } else { - digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); pinMode(ST7735_BACKLIGHT_EN_V05, OUTPUT); + digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); } #endif @@ -515,4 +515,4 @@ bool TFTDisplay::connect() return true; } -#endif \ No newline at end of file +#endif diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 30951cd16..0692d1ef1 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -26,8 +26,8 @@ SX126xInterface::SX126xInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs template bool SX126xInterface::init() { #ifdef SX126X_POWER_EN - digitalWrite(SX126X_POWER_EN, HIGH); pinMode(SX126X_POWER_EN, OUTPUT); + digitalWrite(SX126X_POWER_EN, HIGH); #endif // FIXME: correct logic to default to not using TCXO if no voltage is specified for SX126X_DIO3_TCXO_VOLTAGE diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index 1916c8042..0c5c4dcfa 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -22,8 +22,8 @@ SX128xInterface::SX128xInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs template bool SX128xInterface::init() { #ifdef SX128X_POWER_EN - digitalWrite(SX128X_POWER_EN, HIGH); pinMode(SX128X_POWER_EN, OUTPUT); + digitalWrite(SX128X_POWER_EN, HIGH); #endif #ifdef RF95_FAN_EN @@ -32,12 +32,12 @@ template bool SX128xInterface::init() #endif #if defined(SX128X_RXEN) && (SX128X_RXEN != RADIOLIB_NC) // set not rx or tx mode - digitalWrite(SX128X_RXEN, LOW); // Set low before becoming an output pinMode(SX128X_RXEN, OUTPUT); + digitalWrite(SX128X_RXEN, LOW); // Set low before becoming an output #endif #if defined(SX128X_TXEN) && (SX128X_TXEN != RADIOLIB_NC) - digitalWrite(SX128X_TXEN, LOW); pinMode(SX128X_TXEN, OUTPUT); + digitalWrite(SX128X_TXEN, LOW); #endif RadioLibInterface::init(); From 9e90b4af027daa618ada9c7fa25043ac04d139e8 Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Sat, 2 Dec 2023 13:46:25 +0000 Subject: [PATCH 06/11] Update variant.h (#2930) Co-authored-by: Ben Meadors --- variants/diy/hydra/variant.h | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/diy/hydra/variant.h b/variants/diy/hydra/variant.h index a51b21653..60bb60beb 100644 --- a/variants/diy/hydra/variant.h +++ b/variants/diy/hydra/variant.h @@ -18,6 +18,7 @@ // Radio #define USE_SX1262 // E22-900M30S uses SX1262 +#define USE_SX1268 // E22-400M30S uses SX1268 #define SX126X_MAX_POWER \ 22 // Outputting 22dBm from SX1262 results in ~30dBm E22-900M30S output (module only uses last stage of the YP2233W PA) #define SX126X_DIO3_TCXO_VOLTAGE 1.8 // E22 series TCXO reference voltage is 1.8V From 6ff61b3e04ec583f679db658772fe6ed37315e69 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Sat, 2 Dec 2023 21:47:52 +0100 Subject: [PATCH 07/11] Pico W: Initial Wi-Fi support (#2980) * Pico W: Initial WiFi support: connects, but freezes after a while * Update arduino-pico core to fix hang with Wi-Fi * Add `picow` to workflow since it's different from `pico` now --- .github/workflows/main_matrix.yml | 1 + arch/nrf52/nrf52.ini | 2 +- arch/portduino/portduino.ini | 1 + arch/rp2040/rp2040.ini | 6 +- arch/stm32/stm32wl5e.ini | 2 +- src/graphics/Screen.cpp | 11 +- src/main.cpp | 11 +- src/mesh/NodeDB.cpp | 2 +- src/mesh/api/WiFiServerAPI.h | 2 +- src/mesh/http/ContentHandler.cpp | 2 +- src/mesh/http/ContentHandler.h | 3 +- src/mesh/http/ContentHelper.cpp | 4 +- src/mesh/http/WebServer.cpp | 4 +- src/mesh/{http => wifi}/WiFiAPClient.cpp | 194 +++++++++++++---------- src/mesh/{http => wifi}/WiFiAPClient.h | 4 +- src/modules/AdminModule.h | 6 +- src/mqtt/MQTT.cpp | 2 +- src/platform/esp32/main-esp32.cpp | 2 +- src/sleep.cpp | 2 +- variants/rpipicow/platformio.ini | 6 +- variants/rpipicow/variant.h | 6 +- 21 files changed, 154 insertions(+), 119 deletions(-) rename src/mesh/{http => wifi}/WiFiAPClient.cpp (94%) rename src/mesh/{http => wifi}/WiFiAPClient.h (79%) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 6b6ff1ad7..e53c35bd2 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -123,6 +123,7 @@ jobs: matrix: include: - board: pico + - board: picow - board: rak11310 uses: ./.github/workflows/build_rpi2040.yml with: diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index 1a3631420..5da571cce 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -11,7 +11,7 @@ build_flags = -Isrc/platform/nrf52 build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - + ${arduino_base.build_src_filter} - - - - - - - - - lib_deps= ${arduino_base.lib_deps} diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 8b4ab5d4b..c4b6d5377 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -10,6 +10,7 @@ build_src_filter = - - - + - - - - diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index 38acde1e0..7674fbd52 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -1,8 +1,8 @@ ; Common settings for rp2040 Processor based targets [rp2040_base] -platform = https://github.com/maxgerhardt/platform-raspberrypi.git#0c33219f53faa035e188925ea1324f472e8b93d2 +platform = https://github.com/maxgerhardt/platform-raspberrypi.git#612de5399d68b359053f1307ed223d400aea975c extends = arduino_base -platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#3.2.2 +platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#d2461a14ad5aa920e44508d236c2f459e3befbf8 board_build.core = earlephilhower board_build.filesystem_size = 0.5m @@ -12,7 +12,7 @@ build_flags = -D__PLAT_RP2040__ # -D _POSIX_THREADS build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - + ${arduino_base.build_src_filter} - - - - - - - - lib_ignore = BluetoothOTA diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index f563eec18..cac7110f2 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -13,7 +13,7 @@ build_flags = -DVECT_TAB_OFFSET=0x08000000 build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - - - - - + ${arduino_base.build_src_filter} - - - - - - - - - - - - - board_upload.offset_address = 0x08000000 upload_protocol = stlink diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 2e144e41a..e75a432d4 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -45,7 +45,7 @@ along with this program. If not, see . #ifdef ARCH_ESP32 #include "esp_task_wdt.h" -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "modules/esp32/StoreForwardModule.h" #endif @@ -1618,12 +1618,19 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Connection Failed"); } else if (WiFi.status() == WL_IDLE_STATUS) { display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Idle ... Reconnecting"); - } else { + } +#ifdef ARCH_ESP32 + else { // Codes: // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-reason-code display->drawString(x, y + FONT_HEIGHT_SMALL * 1, WiFi.disconnectReasonName(static_cast(getWifiDisconnectReason()))); } +#else + else { + display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Unkown status: " + String(WiFi.status())); + } +#endif display->drawString(x, y + FONT_HEIGHT_SMALL * 2, "SSID: " + String(wifiName)); diff --git a/src/main.cpp b/src/main.cpp index 5cea142bc..b3671c020 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,9 +32,6 @@ #include // #include -#include "mesh/eth/ethClient.h" -#include "mesh/http/WiFiAPClient.h" - #ifdef ARCH_ESP32 #include "mesh/http/WebServer.h" #include "nimble/NimbleBluetooth.h" @@ -48,10 +45,12 @@ NRF52Bluetooth *nrf52Bluetooth; #if HAS_WIFI #include "mesh/api/WiFiServerAPI.h" +#include "mesh/wifi/WiFiAPClient.h" #endif #if HAS_ETHERNET #include "mesh/api/ethServerAPI.h" +#include "mesh/eth/ethClient.h" #endif #include "mqtt/MQTT.h" @@ -835,11 +834,15 @@ void setup() #ifndef ARCH_PORTDUINO // Initialize Wifi +#if HAS_WIFI initWifi(); +#endif +#if HAS_ETHERNET // Initialize Ethernet initEthernet(); #endif +#endif #ifdef ARCH_ESP32 // Start web server thread. @@ -938,4 +941,4 @@ void loop() mainDelay.delay(delayMsec); } // if (didWake) LOG_DEBUG("wake!\n"); -} \ No newline at end of file +} diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index cb5c27b49..bb079e5c0 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -21,7 +21,7 @@ #include #ifdef ARCH_ESP32 -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "modules/esp32/StoreForwardModule.h" #include #include diff --git a/src/mesh/api/WiFiServerAPI.h b/src/mesh/api/WiFiServerAPI.h index 11b494d23..e436a177d 100644 --- a/src/mesh/api/WiFiServerAPI.h +++ b/src/mesh/api/WiFiServerAPI.h @@ -22,4 +22,4 @@ class WiFiServerPort : public APIServerPort explicit WiFiServerPort(int port); }; -void initApiServer(int port = 4403); +void initApiServer(int port = 4403); \ No newline at end of file diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 2ea2a76a5..4ca37a256 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -5,7 +5,7 @@ #include "main.h" #include "mesh/http/ContentHelper.h" #include "mesh/http/WebServer.h" -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "mqtt/JSON.h" #include "power.h" #include "sleep.h" diff --git a/src/mesh/http/ContentHandler.h b/src/mesh/http/ContentHandler.h index 903d5ee08..987e3ffef 100644 --- a/src/mesh/http/ContentHandler.h +++ b/src/mesh/http/ContentHandler.h @@ -1,5 +1,4 @@ #pragma once - void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer); // Declare some handler functions for the various URLs on the server @@ -34,4 +33,4 @@ class HttpAPI : public PhoneAPI protected: /// Check the current underlying physical link to see if the client is currently connected virtual bool checkIsConnected() override { return true; } // FIXME, be smarter about this -}; +}; \ No newline at end of file diff --git a/src/mesh/http/ContentHelper.cpp b/src/mesh/http/ContentHelper.cpp index 249dcbde6..8f283932b 100644 --- a/src/mesh/http/ContentHelper.cpp +++ b/src/mesh/http/ContentHelper.cpp @@ -1,6 +1,6 @@ #include "mesh/http/ContentHelper.h" -//#include -//#include "main.h" +// #include +// #include "main.h" void replaceAll(std::string &str, const std::string &from, const std::string &to) { diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 2b045c0be..7814f2c29 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -2,7 +2,7 @@ #include "NodeDB.h" #include "graphics/Screen.h" #include "main.h" -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "sleep.h" #include #include @@ -210,4 +210,4 @@ void initWebServer() } else { LOG_ERROR("Web Servers Failed! ;-( \n"); } -} +} \ No newline at end of file diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp similarity index 94% rename from src/mesh/http/WiFiAPClient.cpp rename to src/mesh/wifi/WiFiAPClient.cpp index cc8d4b168..06573fd60 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -1,17 +1,22 @@ -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" #include "configuration.h" #include "main.h" #include "mesh/api/WiFiServerAPI.h" -#include "mesh/http/WebServer.h" #include "mqtt/MQTT.h" #include "target_specific.h" -#include #include #include +#ifndef ARCH_RP2040 +#include "mesh/http/WebServer.h" +#include #include +static void WiFiEvent(WiFiEvent_t event); +#else +#include +#endif #ifndef DISABLE_NTP #include @@ -19,8 +24,6 @@ using namespace concurrency; -static void WiFiEvent(WiFiEvent_t event); - // NTP WiFiUDP ntpUDP; @@ -44,78 +47,6 @@ Syslog syslog(syslogClient); Periodic *wifiReconnect; -static int32_t reconnectWiFi() -{ - const char *wifiName = config.network.wifi_ssid; - const char *wifiPsw = config.network.wifi_psk; - - if (config.network.wifi_enabled && needReconnect) { - - if (!*wifiPsw) // Treat empty password as no password - wifiPsw = NULL; - - needReconnect = false; - - // Make sure we clear old connection credentials - WiFi.disconnect(false, true); - LOG_INFO("Reconnecting to WiFi access point %s\n", wifiName); - - delay(5000); - - if (!WiFi.isConnected()) { - WiFi.begin(wifiName, wifiPsw); - } - } - -#ifndef DISABLE_NTP - if (WiFi.isConnected() && (((millis() - lastrun_ntp) > 43200000) || (lastrun_ntp == 0))) { // every 12 hours - LOG_DEBUG("Updating NTP time from %s\n", config.network.ntp_server); - if (timeClient.update()) { - LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n"); - - struct timeval tv; - tv.tv_sec = timeClient.getEpochTime(); - tv.tv_usec = 0; - - perhapsSetRTC(RTCQualityNTP, &tv); - lastrun_ntp = millis(); - - } else { - LOG_DEBUG("NTP Update failed\n"); - } - } -#endif - - if (config.network.wifi_enabled && !WiFi.isConnected()) { - return 1000; // check once per second - } else { - return 300000; // every 5 minutes - } -} - -bool isWifiAvailable() -{ - - if (config.network.wifi_enabled && (config.network.wifi_ssid[0])) { - return true; - } else { - return false; - } -} - -// Disable WiFi -void deinitWifi() -{ - LOG_INFO("WiFi deinit\n"); - - if (isWifiAvailable()) { - WiFi.disconnect(true); - WiFi.mode(WIFI_MODE_NULL); - LOG_INFO("WiFi Turned Off\n"); - // WiFi.printDiag(Serial); - } -} - static void onNetworkConnected() { if (!APStartupComplete) { @@ -158,7 +89,9 @@ static void onNetworkConnected() syslog.enable(); } +#ifndef ARCH_RP2040 initWebServer(); +#endif initApiServer(); APStartupComplete = true; @@ -169,6 +102,89 @@ static void onNetworkConnected() mqtt->reconnect(); } +static int32_t reconnectWiFi() +{ + const char *wifiName = config.network.wifi_ssid; + const char *wifiPsw = config.network.wifi_psk; + + if (config.network.wifi_enabled && needReconnect) { + + if (!*wifiPsw) // Treat empty password as no password + wifiPsw = NULL; + + needReconnect = false; + + // Make sure we clear old connection credentials +#ifdef ARCH_ESP32 + WiFi.disconnect(false, true); +#else + WiFi.disconnect(false); +#endif + LOG_INFO("Reconnecting to WiFi access point %s\n", wifiName); + + delay(5000); + + if (!WiFi.isConnected()) { + WiFi.begin(wifiName, wifiPsw); + } + } + +#ifndef DISABLE_NTP + if (WiFi.isConnected() && (((millis() - lastrun_ntp) > 43200000) || (lastrun_ntp == 0))) { // every 12 hours + LOG_DEBUG("Updating NTP time from %s\n", config.network.ntp_server); + if (timeClient.update()) { + LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n"); + + struct timeval tv; + tv.tv_sec = timeClient.getEpochTime(); + tv.tv_usec = 0; + + perhapsSetRTC(RTCQualityNTP, &tv); + lastrun_ntp = millis(); + + } else { + LOG_DEBUG("NTP Update failed\n"); + } + } +#endif + + if (config.network.wifi_enabled && !WiFi.isConnected()) { + return 1000; // check once per second + } else { +#ifdef ARCH_RP2040 + onNetworkConnected(); // will only do anything once +#endif + return 300000; // every 5 minutes + } +} + +bool isWifiAvailable() +{ + + if (config.network.wifi_enabled && (config.network.wifi_ssid[0])) { + return true; + } else { + return false; + } +} + +// Disable WiFi +void deinitWifi() +{ + LOG_INFO("WiFi deinit\n"); + + if (isWifiAvailable()) { +#ifdef ARCH_ESP32 + WiFi.disconnect(true, false); +#else + WiFi.disconnect(true); +#endif + WiFi.mode(WIFI_OFF); + LOG_INFO("WiFi Turned Off\n"); + // WiFi.printDiag(Serial); + } +} + // Startup WiFi bool initWifi() { @@ -177,10 +193,10 @@ bool initWifi() const char *wifiName = config.network.wifi_ssid; const char *wifiPsw = config.network.wifi_psk; - createSSLCert(); - +#ifndef ARCH_RP2040 + createSSLCert(); // For WebServer esp_wifi_set_storage(WIFI_STORAGE_RAM); // Disable flash storage for WiFi credentials - +#endif if (!*wifiPsw) // Treat empty password as no password wifiPsw = NULL; @@ -189,17 +205,17 @@ bool initWifi() getMacAddr(dmac); snprintf(ourHost, sizeof(ourHost), "Meshtastic-%02x%02x", dmac[4], dmac[5]); - WiFi.mode(WIFI_MODE_STA); + WiFi.mode(WIFI_STA); WiFi.setHostname(ourHost); - WiFi.onEvent(WiFiEvent); - WiFi.setAutoReconnect(true); - WiFi.setSleep(false); if (config.network.address_mode == meshtastic_Config_NetworkConfig_AddressMode_STATIC && config.network.ipv4_config.ip != 0) { WiFi.config(config.network.ipv4_config.ip, config.network.ipv4_config.gateway, config.network.ipv4_config.subnet, - config.network.ipv4_config.dns, - config.network.ipv4_config.dns); // Wifi wants two DNS servers... set both to the same value + config.network.ipv4_config.dns); } +#ifndef ARCH_RP2040 + WiFi.onEvent(WiFiEvent); + WiFi.setAutoReconnect(true); + WiFi.setSleep(false); // This is needed to improve performance. esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving @@ -218,7 +234,7 @@ bool initWifi() wifiDisconnectReason = info.wifi_sta_disconnected.reason; }, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED); - +#endif LOG_DEBUG("JOINING WIFI soon: ssid=%s\n", wifiName); wifiReconnect = new Periodic("WifiConnect", reconnectWiFi); } @@ -229,6 +245,7 @@ bool initWifi() } } +#ifndef ARCH_RP2040 // Called by the Espressif SDK to static void WiFiEvent(WiFiEvent_t event) { @@ -369,8 +386,9 @@ static void WiFiEvent(WiFiEvent_t event) break; } } +#endif uint8_t getWifiDisconnectReason() { return wifiDisconnectReason; -} +} \ No newline at end of file diff --git a/src/mesh/http/WiFiAPClient.h b/src/mesh/wifi/WiFiAPClient.h similarity index 79% rename from src/mesh/http/WiFiAPClient.h rename to src/mesh/wifi/WiFiAPClient.h index 0c08c567b..6625d3e46 100644 --- a/src/mesh/http/WiFiAPClient.h +++ b/src/mesh/wifi/WiFiAPClient.h @@ -5,7 +5,7 @@ #include #include -#ifdef ARCH_ESP32 +#if defined(HAS_WIFI) && !defined(ARCH_PORTDUINO) #include #endif @@ -19,4 +19,4 @@ void deinitWifi(); bool isWifiAvailable(); -uint8_t getWifiDisconnectReason(); +uint8_t getWifiDisconnectReason(); \ No newline at end of file diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index eb06e7b83..6ecc88829 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -1,7 +1,7 @@ #pragma once #include "ProtobufModule.h" -#ifdef ARCH_ESP32 -#include "mesh/http/WiFiAPClient.h" +#if HAS_WIFI +#include "mesh/wifi/WiFiAPClient.h" #endif /** @@ -50,4 +50,4 @@ class AdminModule : public ProtobufModule void reboot(int32_t seconds); }; -extern AdminModule *adminModule; +extern AdminModule *adminModule; \ No newline at end of file diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 29a634922..a97aa5255 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -7,9 +7,9 @@ #include "mesh/Router.h" #include "mesh/generated/meshtastic/mqtt.pb.h" #include "mesh/generated/meshtastic/telemetry.pb.h" -#include "mesh/http/WiFiAPClient.h" #include "sleep.h" #if HAS_WIFI +#include "mesh/wifi/WiFiAPClient.h" #include #endif #include "mqtt/JSON.h" diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 833e058d8..7da41512e 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -7,7 +7,7 @@ #include "nimble/NimbleBluetooth.h" #endif #include "BleOta.h" -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "meshUtils.h" #include "sleep.h" diff --git a/src/sleep.cpp b/src/sleep.cpp index b0f4aec88..464486d00 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -11,7 +11,7 @@ #ifdef ARCH_ESP32 #include "esp32/pm.h" #include "esp_pm.h" -#include "mesh/http/WiFiAPClient.h" +#include "mesh/wifi/WiFiAPClient.h" #include "rom/rtc.h" #include #include diff --git a/variants/rpipicow/platformio.ini b/variants/rpipicow/platformio.ini index 3228e4c24..4c8cf992d 100644 --- a/variants/rpipicow/platformio.ini +++ b/variants/rpipicow/platformio.ini @@ -8,8 +8,10 @@ upload_protocol = picotool build_flags = ${rp2040_base.build_flags} -DRPI_PICO -Ivariants/rpipicow - -DDEBUG_RP2040_PORT=Serial -DHW_SPI1_DEVICE -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" + -fexceptions # for exception handling in MQTT +build_src_filter = ${rp2040_base.build_src_filter} + lib_deps = - ${rp2040_base.lib_deps} \ No newline at end of file + ${rp2040_base.lib_deps} + ${networking_base.lib_deps} \ No newline at end of file diff --git a/variants/rpipicow/variant.h b/variants/rpipicow/variant.h index abbd1c465..c48b901ac 100644 --- a/variants/rpipicow/variant.h +++ b/variants/rpipicow/variant.h @@ -4,6 +4,10 @@ #define ARDUINO_ARCH_AVR +#ifndef HAS_WIFI +#define HAS_WIFI 1 +#endif + #define USE_SH1106 1 // default I2C pins: @@ -46,4 +50,4 @@ #define SX126X_RESET LORA_RESET #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 -#endif +#endif \ No newline at end of file From 31c4693c662dee0a6cab08db9ef9cfbad015ac0d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 2 Dec 2023 15:50:17 -0600 Subject: [PATCH 08/11] Missed the version bump apparently --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 972a6f6de..8830a26a5 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 2 -build = 14 +build = 15 From 1f931a5e55a7a48ab62e2140d69e5ed6e0e9a3f3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:19:29 -0600 Subject: [PATCH 09/11] [create-pull-request] automated change (#2981) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 8830a26a5..c95d5701a 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 2 -build = 15 +build = 16 From 1c22d2c885194d267f4174eb8f6884ecc0f8af4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 3 Dec 2023 10:56:13 +0100 Subject: [PATCH 10/11] switch onebutton back to PIO registry, since they finally updated the lib there --- arch/stm32/stm32wl5e.ini | 2 +- platformio.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index cac7110f2..4e47be8c3 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -26,4 +26,4 @@ lib_deps = https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 lib_ignore = - https://github.com/mathertel/OneButton#2.1.0 \ No newline at end of file + mathertel/OneButton \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 451fe3f1a..f176823d1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -69,7 +69,7 @@ monitor_speed = 115200 lib_deps = https://github.com/meshtastic/esp8266-oled-ssd1306.git#b38094e03dfa964fbc0e799bc374e91a605c1223 ; ESP8266_SSD1306 - https://github.com/mathertel/OneButton#2.1.0 ; OneButton library for non-blocking button debounce + mathertel/OneButton@^2.5.0 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 https://github.com/meshtastic/TinyGPSPlus.git#076e8d2c8fb702d9be5b08c55b93ff76f8af7e61 https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3 From 07fc5df9c1b46b98ee6c80bb71e021033add3751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 3 Dec 2023 13:02:14 +0100 Subject: [PATCH 11/11] update trunk and linters to latest version --- .trunk/trunk.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index e31b026f4..645d3863a 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,25 @@ version: 0.1 cli: - version: 1.17.1 + version: 1.17.2 plugins: sources: - id: trunk - ref: v1.2.6 + ref: v1.3.0 uri: https://github.com/trunk-io/plugins lint: enabled: - bandit@1.7.5 - - checkov@3.0.16 - - terrascan@1.18.3 - - trivy@0.46.1 - - trufflehog@3.62.1 + - checkov@3.1.9 + - terrascan@1.18.5 + - trivy@0.47.0 + - trufflehog@3.63.2-rc0 - taplo@0.8.1 - - ruff@0.1.3 - - yamllint@1.32.0 + - ruff@0.1.6 + - yamllint@1.33.0 - isort@5.12.0 - markdownlint@0.37.0 - oxipng@9.0.0 - - svgo@3.0.2 + - svgo@3.0.5 - actionlint@1.6.26 - flake8@6.1.0 - hadolint@2.12.0 @@ -27,9 +27,9 @@ lint: - shellcheck@0.9.0 - black@23.9.1 - git-diff-check - - gitleaks@8.18.0 + - gitleaks@8.18.1 - clang-format@16.0.3 - - prettier@3.0.3 + - prettier@3.1.0 runtimes: enabled: - python@3.10.8