23
23
#include " Adafruit_MQTT.h"
24
24
#include " Adafruit_MQTT_Client.h"
25
25
#include " Arduino.h"
26
+ #include < WiFiClient.h>
26
27
#include < WiFiClientSecure.h>
27
28
extern Wippersnapper WS;
28
29
@@ -42,7 +43,6 @@ class ws_networking_pico : public Wippersnapper {
42
43
ws_networking_pico () : Wippersnapper() {
43
44
_ssid = 0 ;
44
45
_pass = 0 ;
45
- _mqtt_client = new WiFiClientSecure;
46
46
}
47
47
48
48
/* *************************************************************************/
@@ -51,8 +51,10 @@ class ws_networking_pico : public Wippersnapper {
51
51
*/
52
52
/* *************************************************************************/
53
53
~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;
56
58
}
57
59
58
60
/* *******************************************************/
@@ -154,19 +156,22 @@ class ws_networking_pico : public Wippersnapper {
154
156
*/
155
157
/* *******************************************************/
156
158
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 );
163
169
} 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 );
165
174
}
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 );
170
175
}
171
176
172
177
/* *******************************************************/
@@ -197,10 +202,13 @@ class ws_networking_pico : public Wippersnapper {
197
202
const char *connectionType () { return " Pico" ; }
198
203
199
204
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
204
212
205
213
const char *_aio_root_ca_staging =
206
214
" -----BEGIN CERTIFICATE-----\n "
0 commit comments