Skip to content

Commit e539047

Browse files
committed
add wifi changes to pico, fix pio ini to avoid compile override
1 parent d6c75ad commit e539047

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ board_build.core = earlephilhower
107107
board_build.filesystem_size = 0.5m
108108
build_flags = -DUSE_TINYUSB
109109
; Once https://github.com/platformio/platformio-core > 6.1.11 these can be removed
110-
lib_ignore = WiFiNINA, Adafruit Zero DMA Library
110+
lib_ignore = WiFiNINA, WiFi101, Adafruit Zero DMA Library
111111
lib_compat_mode = soft ; can be strict once pio detects SleepyDog on RP2040
112112

113113
; ESP32-x Boards ;

src/network_interfaces/ws_networking_pico.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Adafruit_MQTT.h"
2424
#include "Adafruit_MQTT_Client.h"
2525
#include "Arduino.h"
26+
#include <WiFiClient.h>
2627
#include <WiFiClientSecure.h>
2728
extern Wippersnapper WS;
2829

@@ -42,7 +43,6 @@ class ws_networking_pico : public Wippersnapper {
4243
ws_networking_pico() : Wippersnapper() {
4344
_ssid = 0;
4445
_pass = 0;
45-
_mqtt_client = new WiFiClientSecure;
4646
}
4747

4848
/**************************************************************************/
@@ -51,8 +51,10 @@ class ws_networking_pico : public Wippersnapper {
5151
*/
5252
/**************************************************************************/
5353
~ws_networking_pico() {
54-
if (_mqtt_client)
55-
delete _mqtt_client;
54+
if (_mqtt_client_secure)
55+
delete _mqtt_client_secure;
56+
if (_mqtt_client_secure)
57+
delete _mqtt_client_secure;
5658
}
5759

5860
/********************************************************/
@@ -154,19 +156,22 @@ class ws_networking_pico : public Wippersnapper {
154156
*/
155157
/********************************************************/
156158
void setupMQTTClient(const char *clientID) {
157-
// Set CA cert depending on the server we're connecting to
158-
// compare WS._config.aio_url to "io.adafruit.com"
159-
if (strcmp(WS._config.aio_url, "io.adafruit.com") == 0) {
160-
_mqtt_client->setCACert(_aio_root_ca_prod);
161-
} else if (strcmp(WS._config.aio_url, "io.adafruit.us") == 0) {
162-
_mqtt_client->setCACert(_aio_root_ca_staging);
159+
if (strcmp(WS._config.aio_url, "io.adafruit.com") == 0 ||
160+
strcmp(WS._config.aio_url, "io.adafruit.us") == 0) {
161+
_mqtt_client_secure = new WiFiClientSecure();
162+
_mqtt_client_secure->setCACert(
163+
strcmp(WS._config.aio_url, "io.adafruit.com") == 0
164+
? _aio_root_ca_prod
165+
: _aio_root_ca_staging);
166+
WS._mqtt = new Adafruit_MQTT_Client(
167+
_mqtt_client_secure, WS._config.aio_url, WS._config.io_port, clientID,
168+
WS._config.aio_user, WS._config.aio_key);
163169
} else {
164-
_mqtt_client->setInsecure();
170+
_mqtt_client_insecure = new WiFiClient();
171+
WS._mqtt = new Adafruit_MQTT_Client(
172+
_mqtt_client_insecure, WS._config.aio_url, WS._config.io_port,
173+
clientID, WS._config.aio_user, WS._config.aio_key);
165174
}
166-
167-
WS._mqtt = new Adafruit_MQTT_Client(
168-
_mqtt_client, WS._config.aio_url, WS._config.io_port, clientID,
169-
WS._config.aio_user, WS._config.aio_key);
170175
}
171176

172177
/********************************************************/
@@ -197,10 +202,13 @@ class ws_networking_pico : public Wippersnapper {
197202
const char *connectionType() { return "Pico"; }
198203

199204
protected:
200-
const char *_ssid; ///< WiFi SSID
201-
const char *_pass; ///< WiFi password
202-
WiFiClientSecure *_mqtt_client; ///< Pointer to a secure MQTT client object
203-
WiFiMulti _wifiMulti; ///< WiFiMulti object for multi-network mode
205+
const char *_ssid; ///< WiFi SSID
206+
const char *_pass; ///< WiFi password
207+
WiFiClient
208+
*_mqtt_client_insecure; ///< Pointer to an insecure WiFi client object
209+
WiFiClientSecure
210+
*_mqtt_client_secure; ///< Pointer to a secure WiFi client object
211+
WiFiMulti _wifiMulti; ///< WiFiMulti object for multi-network mode
204212

205213
const char *_aio_root_ca_staging =
206214
"-----BEGIN CERTIFICATE-----\n"

0 commit comments

Comments
 (0)