Skip to content

Commit 2e77858

Browse files
brentrutyeth
authored andcommitted
add wifi changes to pico, fix pio ini to avoid compile override
1 parent 19e634a commit 2e77858

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
@@ -110,7 +110,7 @@ board_build.core = earlephilhower
110110
board_build.filesystem_size = 0.5m
111111
build_flags = -DUSE_TINYUSB
112112
; Once https://github.com/platformio/platformio-core > 6.1.11 these can be removed
113-
lib_ignore = WiFiNINA, Adafruit Zero DMA Library
113+
lib_ignore = WiFiNINA, WiFi101, Adafruit Zero DMA Library
114114
lib_compat_mode = soft ; can be strict once pio detects SleepyDog on RP2040
115115

116116

src/network_interfaces/ws_networking_pico.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "Adafruit_MQTT.h"
2828
#include "Adafruit_MQTT_Client.h"
2929
#include "Arduino.h"
30+
#include <WiFiClient.h>
3031
#include <WiFiClientSecure.h>
3132
extern Wippersnapper WS;
3233

@@ -46,7 +47,6 @@ class ws_networking_pico : public Wippersnapper {
4647
ws_networking_pico() : Wippersnapper() {
4748
_ssid = 0;
4849
_pass = 0;
49-
_mqtt_client = new WiFiClientSecure;
5050
}
5151

5252
/**************************************************************************/
@@ -55,8 +55,10 @@ class ws_networking_pico : public Wippersnapper {
5555
*/
5656
/**************************************************************************/
5757
~ws_networking_pico() {
58-
if (_mqtt_client)
59-
delete _mqtt_client;
58+
if (_mqtt_client_secure)
59+
delete _mqtt_client_secure;
60+
if (_mqtt_client_secure)
61+
delete _mqtt_client_secure;
6062
}
6163

6264
/********************************************************/
@@ -174,19 +176,22 @@ class ws_networking_pico : public Wippersnapper {
174176
*/
175177
/********************************************************/
176178
void setupMQTTClient(const char *clientID) {
177-
// Set CA cert depending on the server we're connecting to
178-
// compare WS._config.aio_url to "io.adafruit.com"
179-
if (strcmp(WS._config.aio_url, "io.adafruit.com") == 0) {
180-
_mqtt_client->setCACert(_aio_root_ca_prod);
181-
} else if (strcmp(WS._config.aio_url, "io.adafruit.us") == 0) {
182-
_mqtt_client->setCACert(_aio_root_ca_staging);
179+
if (strcmp(WS._config.aio_url, "io.adafruit.com") == 0 ||
180+
strcmp(WS._config.aio_url, "io.adafruit.us") == 0) {
181+
_mqtt_client_secure = new WiFiClientSecure();
182+
_mqtt_client_secure->setCACert(
183+
strcmp(WS._config.aio_url, "io.adafruit.com") == 0
184+
? _aio_root_ca_prod
185+
: _aio_root_ca_staging);
186+
WS._mqtt = new Adafruit_MQTT_Client(
187+
_mqtt_client_secure, WS._config.aio_url, WS._config.io_port, clientID,
188+
WS._config.aio_user, WS._config.aio_key);
183189
} else {
184-
_mqtt_client->setInsecure();
190+
_mqtt_client_insecure = new WiFiClient();
191+
WS._mqtt = new Adafruit_MQTT_Client(
192+
_mqtt_client_insecure, WS._config.aio_url, WS._config.io_port,
193+
clientID, WS._config.aio_user, WS._config.aio_key);
185194
}
186-
187-
WS._mqtt = new Adafruit_MQTT_Client(
188-
_mqtt_client, WS._config.aio_url, WS._config.io_port, clientID,
189-
WS._config.aio_user, WS._config.aio_key);
190195
}
191196

192197
/********************************************************/
@@ -217,10 +222,13 @@ class ws_networking_pico : public Wippersnapper {
217222
const char *connectionType() { return "Pico"; }
218223

219224
protected:
220-
const char *_ssid; ///< WiFi SSID
221-
const char *_pass; ///< WiFi password
222-
WiFiClientSecure *_mqtt_client; ///< Pointer to a secure MQTT client object
223-
WiFiMulti _wifiMulti; ///< WiFiMulti object for multi-network mode
225+
const char *_ssid; ///< WiFi SSID
226+
const char *_pass; ///< WiFi password
227+
WiFiClient
228+
*_mqtt_client_insecure; ///< Pointer to an insecure WiFi client object
229+
WiFiClientSecure
230+
*_mqtt_client_secure; ///< Pointer to a secure WiFi client object
231+
WiFiMulti _wifiMulti; ///< WiFiMulti object for multi-network mode
224232

225233
const char *_aio_root_ca_staging =
226234
"-----BEGIN CERTIFICATE-----\n"

0 commit comments

Comments
 (0)