11
11
* please support Adafruit and open-source hardware by purchasing
12
12
* products from Adafruit!
13
13
*
14
- * Copyright (c) Brent Rubell 2020-2021 for Adafruit Industries.
14
+ * Copyright (c) Brent Rubell 2020-2025 for Adafruit Industries.
15
15
*
16
16
* MIT license, all text here must be included in any redistribution.
17
17
*
25
25
#include " Arduino.h"
26
26
#include " SPI.h"
27
27
#include " WiFiNINA.h"
28
- #include " Wippersnapper.h"
28
+ #include " Wippersnapper_V2.h"
29
+ #include " ../../helpers/ws_helper_macros.h"
29
30
30
- #define NINAFWVER \
31
- " 1.7.7" /* !< min. nina-fw version compatible with this library. */
31
+ #define NINAFWVER " 2.0.0-rc.0+adafruit" /* !< min. nina-fw version compatible with this library. */
32
32
#define AIRLIFT_CONNECT_TIMEOUT_MS 20000 /* !< Connection timeout (in ms) */
33
33
#define AIRLIFT_CONNECT_RETRY_DELAY_MS 200 /* !< delay time between retries. */
34
34
35
35
#define SPIWIFI SPI /* !< Instance of SPI interface used by an AirLift. */
36
36
37
- extern Wippersnapper WS ; // /< Global Wippersnapper instance
37
+ extern Wippersnapper_V2 WsV2 ; // /< Wippersnapper client instance
38
38
/* ***************************************************************************/
39
39
/* !
40
40
@brief Class for using the AirLift Co-Processor network iface.
41
41
*/
42
42
/* ***************************************************************************/
43
- class ws_wifi_airlift : public Wippersnapper {
43
+ class ws_wifi_airlift : public Wippersnapper_V2 {
44
44
45
45
public:
46
46
/* *************************************************************************/
47
47
/* !
48
48
@brief Initializes the Adafruit IO class for AirLift devices.
49
49
*/
50
50
/* *************************************************************************/
51
- ws_wifi_airlift () : Wippersnapper () {
51
+ ws_wifi_airlift () : Wippersnapper_V2 () {
52
52
_ssPin = SPIWIFI_SS; // 10;
53
53
_ackPin = SPIWIFI_ACK; // 7;
54
54
_rstPin = SPIWIFI_RESET; // 5; // should be 7 on PyPortals
@@ -72,8 +72,8 @@ class ws_wifi_airlift : public Wippersnapper {
72
72
*/
73
73
/* *************************************************************************/
74
74
~ws_wifi_airlift () {
75
- if (_mqtt )
76
- delete _mqtt ;
75
+ if (_mqttV2 )
76
+ delete _mqttV2 ;
77
77
}
78
78
79
79
/* *********************************************************/
@@ -97,8 +97,8 @@ class ws_wifi_airlift : public Wippersnapper {
97
97
*/
98
98
/* *********************************************************/
99
99
void set_ssid_pass () {
100
- _ssid = WS. _config .network .ssid ;
101
- _pass = WS. _config .network .pass ;
100
+ _ssid = WsV2. _configV2 .network .ssid ;
101
+ _pass = WsV2. _configV2 .network .pass ;
102
102
}
103
103
104
104
/* **********************************************************/
@@ -231,7 +231,7 @@ class ws_wifi_airlift : public Wippersnapper {
231
231
void getMacAddr () {
232
232
uint8_t mac[6 ] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
233
233
WiFi.macAddress (mac);
234
- memcpy (WS. _macAddr , mac, sizeof (mac));
234
+ memcpy (WsV2. _macAddrV2 , mac, sizeof (mac));
235
235
}
236
236
237
237
/* *******************************************************/
@@ -250,9 +250,9 @@ class ws_wifi_airlift : public Wippersnapper {
250
250
*/
251
251
/* *******************************************************/
252
252
void setupMQTTClient (const char *clientID) {
253
- WS. _mqtt = new Adafruit_MQTT_Client (
254
- _mqtt_client, WS. _config .aio_url , WS. _config .io_port , clientID,
255
- WS. _config .aio_user , WS. _config .aio_key );
253
+ WsV2. _mqttV2 = new Adafruit_MQTT_Client (
254
+ _mqtt_client, WsV2. _configV2 .aio_url , WsV2. _configV2 .io_port , clientID,
255
+ WsV2. _configV2 .aio_user , WsV2. _configV2 .aio_key );
256
256
}
257
257
258
258
/* *******************************************************/
@@ -300,7 +300,7 @@ class ws_wifi_airlift : public Wippersnapper {
300
300
/* *************************************************************************/
301
301
void _connect () {
302
302
if (strlen (_ssid) == 0 ) {
303
- _status = WS_SSID_INVALID; // possibly unneccesary as already checking
303
+ _statusV2 = WS_SSID_INVALID; // possibly unneccesary as already checking
304
304
// elsewhere
305
305
} else {
306
306
// disconnect from possible previous connection
@@ -310,16 +310,16 @@ class ws_wifi_airlift : public Wippersnapper {
310
310
_wifi->end ();
311
311
delay (100 );
312
312
_wifi->begin ();
313
- feedWDT ();
313
+ WsV2. feedWDTV2 ();
314
314
// reset the esp32 if possible
315
315
resetAirLift ();
316
- feedWDT ();
316
+ WsV2. feedWDTV2 ();
317
317
318
318
WS_DEBUG_PRINT (" ESP32 booted, version: " );
319
319
WS_PRINTER.flush ();
320
320
WS_DEBUG_PRINTLN (WiFi.firmwareVersion ());
321
321
WS_PRINTER.flush ();
322
- feedWDT ();
322
+ WsV2. feedWDTV2 ();
323
323
324
324
// validate co-processor's firmware version
325
325
if (!firmwareCheck ()) {
@@ -330,26 +330,25 @@ class ws_wifi_airlift : public Wippersnapper {
330
330
WS_DEBUG_PRINT (" Connecting to " );
331
331
WS_DEBUG_PRINTLN (_ssid);
332
332
WS_PRINTER.flush ();
333
- feedWDT ();
333
+ WsV2. feedWDTV2 ();
334
334
WiFi.begin (_ssid, _pass);
335
- _status = WS_NET_DISCONNECTED;
335
+ _statusV2 = WS_NET_DISCONNECTED;
336
336
337
337
// Use the macro to retry the status check until connected / timed out
338
338
int lastResult = -1 ;
339
339
RETRY_FUNCTION_UNTIL_TIMEOUT (
340
340
[]() -> int { return WiFi.status (); }, // Function call each cycle
341
- int , // return type
342
341
lastResult, // return variable
343
342
[](int status) { return status == WL_CONNECTED; }, // check
344
343
AIRLIFT_CONNECT_TIMEOUT_MS, // timeout interval (ms)
345
344
AIRLIFT_CONNECT_RETRY_DELAY_MS); // interval between retries
346
345
347
346
if (lastResult == WL_CONNECTED) {
348
- _status = WS_NET_CONNECTED;
347
+ _statusV2 = WS_NET_CONNECTED;
349
348
// wait 2seconds for connection to stabilize
350
349
WS_DELAY_WITH_WDT (2000 );
351
350
} else {
352
- _status = WS_NET_DISCONNECTED; // maybe connect failed instead?
351
+ _statusV2 = WS_NET_DISCONNECTED; // maybe connect failed instead?
353
352
}
354
353
}
355
354
}
0 commit comments