Fix review findings on Pico W WiFi/BLE

This commit is contained in:
Michael Graff
2026-09-06 20:43:37 -05:00
parent 88cc014f55
commit b9fa450f52
4 changed files with 20 additions and 11 deletions
+2 -1
View File
@@ -2158,7 +2158,8 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
}
#ifdef WIFI_SSID
// local console only: these are credentials, and remote admin has no business with them
// not accepted from the remote mesh CLI (timestamp != 0): these are credentials. The app
// over USB/BLE/WiFi and the serial console (timestamp 0) may set them.
if (sender_timestamp == 0) {
if (memcmp(command, "set wifi.ssid ", 14) == 0) {
StrHelper::strncpy(_prefs.wifi_ssid, &command[14], sizeof(_prefs.wifi_ssid));
+13 -8
View File
@@ -41,7 +41,11 @@ MultiSerialInterface interface_manager;
#define TCP_PORT 5000
#endif
#ifndef WIFI_RETRY_INTERVAL
#define WIFI_RETRY_INTERVAL 30000 // millis between reconnect attempts
#if defined(RP2040_PLATFORM)
#define WIFI_RETRY_INTERVAL 30000 // each attempt blocks loop(), so retry less often
#else
#define WIFI_RETRY_INTERVAL 10000 // millis between reconnect attempts
#endif
#endif
#ifndef WIFI_RETRY_TIMEOUT
#define WIFI_RETRY_TIMEOUT 5000 // RP2040: cap on how long one join may block loop()
@@ -120,8 +124,8 @@ void halt() {
#ifdef WIFI_SSID
bool wifi_needs_reconnect = false;
unsigned long last_wifi_reconnect_attempt = 0;
const char* wifi_ssid = WIFI_SSID; // replaced by stored prefs, if set
const char* wifi_pwd = WIFI_PWD;
char wifi_ssid[33] = WIFI_SSID; // replaced by stored prefs at boot, if set
char wifi_pwd[64] = WIFI_PWD;
bool wifi_was_connected = false;
#endif
@@ -220,13 +224,14 @@ void setup() {
#endif
// stored credentials win over the build-time ones ('set wifi.ssid <x>' over USB serial).
// they are taken as a pair, so 'set wifi.ssid' alone gives an open-network join, not a
// silent fallback to the build-time password of a different network.
// they are taken as a pair, so 'set wifi.ssid' alone gives an empty password, not a
// silent fallback to the build-time password of a different network. Copied out of prefs
// so 'set wifi.*' edits only take effect on reboot, as their replies promise.
// (No NULL-for-open-network: the RP2040 core does strlen() on the password unguarded.)
if (the_mesh.getNodePrefs()->wifi_ssid[0]) {
wifi_ssid = the_mesh.getNodePrefs()->wifi_ssid;
wifi_pwd = the_mesh.getNodePrefs()->wifi_pwd;
strcpy(wifi_ssid, the_mesh.getNodePrefs()->wifi_ssid);
strcpy(wifi_pwd, the_mesh.getNodePrefs()->wifi_pwd);
}
if (wifi_pwd[0] == 0) wifi_pwd = NULL; // NULL (not "") selects an open network
WIFI_DEBUG_PRINTLN("connecting to %s", wifi_ssid);
#if defined(RP2040_PLATFORM)
@@ -1,3 +1,5 @@
// only built when the env enables the core BLE stack (build_as_lib.py globs this dir)
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_BLUETOOTH
#include "SerialBLEInterface.h"
#include <BluetoothLock.h>
#include <stdio.h>
@@ -196,3 +198,4 @@ size_t SerialBLEInterface::checkRecvFrame(uint8_t dest[]) {
BLE_DEBUG_PRINTLN("readBytes: sz=%u, hdr=%u", (unsigned)len, dest[0]);
return len;
}
#endif
+2 -2
View File
@@ -92,8 +92,8 @@ build_flags = ${rpi_picow.build_flags}
-D ENABLE_USB_INTERFACE
-D PIO_FRAMEWORK_ARDUINO_ENABLE_BLUETOOTH
-D BLE_PIN_CODE=123456
-D BLE_DEBUG_LOGGING=1
-D WIFI_DEBUG_LOGGING=1
; NOTE: DO NOT ENABLE --> -D BLE_DEBUG_LOGGING=1 (shares Serial with the USB interface)
; NOTE: DO NOT ENABLE --> -D WIFI_DEBUG_LOGGING=1
-D WIFI_SSID='"myssid"'
-D WIFI_PWD='"mypwd"'
; -D MESH_PACKET_LOGGING=1