27
27
#include " Adafruit_MQTT.h"
28
28
#include " Adafruit_MQTT_Client.h"
29
29
#include " Arduino.h"
30
+ #include < WiFiClient.h>
30
31
#include < WiFiClientSecure.h>
31
32
extern Wippersnapper WS;
32
33
@@ -46,7 +47,6 @@ class ws_networking_pico : public Wippersnapper {
46
47
ws_networking_pico () : Wippersnapper() {
47
48
_ssid = 0 ;
48
49
_pass = 0 ;
49
- _mqtt_client = new WiFiClientSecure;
50
50
}
51
51
52
52
/* *************************************************************************/
@@ -55,8 +55,10 @@ class ws_networking_pico : public Wippersnapper {
55
55
*/
56
56
/* *************************************************************************/
57
57
~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;
60
62
}
61
63
62
64
/* *******************************************************/
@@ -174,19 +176,22 @@ class ws_networking_pico : public Wippersnapper {
174
176
*/
175
177
/* *******************************************************/
176
178
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 );
183
189
} 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 );
185
194
}
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 );
190
195
}
191
196
192
197
/* *******************************************************/
@@ -217,10 +222,13 @@ class ws_networking_pico : public Wippersnapper {
217
222
const char *connectionType () { return " Pico" ; }
218
223
219
224
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
224
232
225
233
const char *_aio_root_ca_staging =
226
234
" -----BEGIN CERTIFICATE-----\n "
0 commit comments