Skip to content

Commit c320f1c

Browse files
author
brentru
committed
fixup airlift compile with include
1 parent 3a064f7 commit c320f1c

File tree

1 file changed

+152
-145
lines changed

1 file changed

+152
-145
lines changed

src/wifi/AdafruitIO_AIRLIFT.h

Lines changed: 152 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -19,173 +19,180 @@
1919
#ifndef ADAFRUITIO_AIRLIFT_H
2020
#define ADAFRUITIO_AIRLIFT_H
2121

22+
#include "Arduino.h"
2223
#include "AdafruitIO.h"
24+
#include "WiFiNINA.h"
25+
#include "SPI.h"
2326
#include "Adafruit_MQTT.h"
2427
#include "Adafruit_MQTT_Client.h"
25-
#include "Arduino.h"
26-
#include "SPI.h"
27-
#include "WiFiNINA.h"
2828

29-
#define NINAFWVER "1.0.0" /*!< nina-fw version compatible with this library. */
29+
#define NINAFWVER "1.0.0" /*!< nina-fw version compatible with this library. */
3030

3131
/****************************************************************************/
32-
/*!
32+
/*!
3333
@brief Class that stores functions for interacting with AirLift Devices
3434
*/
3535
/****************************************************************************/
3636
class AdafruitIO_AIRLIFT : public AdafruitIO {
3737

38-
public:
39-
/**************************************************************************/
40-
/*!
41-
@brief Initializes the Adafruit IO class for AirLift devices.
42-
@param user
43-
A reference to the Adafruit IO user, shared by AdafruitIO.
44-
@param key
45-
A reference to the Adafruit IO Key, shared by AdafruitIO.
46-
@param ssid
47-
A reference to the WiFi network SSID.
48-
@param pass
49-
A reference to the WiFi network password.
50-
@param ssPin
51-
A reference to the ESP32_SS Pin.
52-
@param ackPin
53-
A reference to the ESP32_ACK Pin.
54-
@param rstPin
55-
A reference to the ESP32_RST Pin.
56-
@param gpio0Pin
57-
A reference to the gpio0Pin Pin.
58-
@param wifi
59-
A reference to a SPIClass
60-
*/
61-
/**************************************************************************/
62-
AdafruitIO_AIRLIFT(const char *user, const char *key, const char *ssid,
63-
const char *pass, int ssPin=10, int ackPin=9, int rstPin=6,
64-
int gpio0Pin=-1, SPIClass *wifi)
65-
: AdafruitIO(user, key) {
66-
_wifi = wifi;
67-
_ssPin = ssPin;
68-
_ackPin = ackPin;
69-
_rstPin = rstPin;
70-
_gpio0Pin = gpio0Pin;
71-
_ssid = ssid;
72-
_pass = pass;
73-
_mqtt_client = new WiFiSSLClient;
74-
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
75-
_http_client = new WiFiSSLClient;
76-
_http = new HttpClient(*_http_client, _host, _http_port);
77-
}
78-
79-
/**************************************************************************/
80-
/*!
81-
@brief Destructor for the Adafruit IO AirLift class.
82-
*/
83-
/**************************************************************************/
84-
~AdafruitIO_AIRLIFT() {
85-
if (_mqtt_client)
86-
delete _http_client;
87-
if (_http_client)
88-
delete _mqtt_client;
89-
if (_mqtt)
90-
delete _mqtt;
91-
if (_http)
92-
delete _http;
93-
}
94-
95-
/********************************************************/
96-
/*!
97-
@brief Checks the version of an ESP32 module against
98-
NINAFWVER. Raises an error if the firmware needs to be
99-
upgraded.
100-
*/
101-
/********************************************************/
102-
void firmwareCheck() {
103-
_fv = WiFi.firmwareVersion();
104-
if (_fv < NINAFWVER) {
105-
AIO_DEBUG_PRINTLN("Please upgrade the firmware on the ESP module");
38+
public:
39+
/**************************************************************************/
40+
/*!
41+
@brief Initializes the Adafruit IO class for AirLift devices.
42+
@param user
43+
A reference to the Adafruit IO user, shared by AdafruitIO.
44+
@param key
45+
A reference to the Adafruit IO Key, shared by AdafruitIO.
46+
@param ssid
47+
A reference to the WiFi network SSID.
48+
@param pass
49+
A reference to the WiFi network password.
50+
@param ssPin
51+
A reference to the ESP32_SS Pin.
52+
@param ackPin
53+
A reference to the ESP32_ACK Pin.
54+
@param rstPin
55+
A reference to the ESP32_RST Pin.
56+
@param gpio0Pin
57+
A reference to the gpio0Pin Pin.
58+
@param wifi
59+
A reference to a SPIClass
60+
*/
61+
/**************************************************************************/
62+
AdafruitIO_AIRLIFT(const char *user, const char *key, const char *ssid, const char *pass, int ssPin, int ackPin, int rstPin, int gpio0Pin, SPIClass* wifi) : AdafruitIO(user, key)
63+
{
64+
_wifi = wifi;
65+
_ssPin = ssPin;
66+
_ackPin = ackPin;
67+
_rstPin = rstPin;
68+
_gpio0Pin = gpio0Pin;
69+
_ssid = ssid;
70+
_pass = pass;
71+
_mqtt_client = new WiFiSSLClient;
72+
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
73+
_http_client = new WiFiSSLClient;
74+
_http = new HttpClient(*_http_client, _host, _http_port);
10675
}
107-
}
10876

109-
/********************************************************/
110-
/*!
111-
@brief Returns the network status of an ESP32 module.
112-
@return aio_status_t
113-
*/
114-
/********************************************************/
115-
aio_status_t networkStatus() {
116-
switch (WiFi.status()) {
117-
case WL_CONNECTED:
118-
return AIO_NET_CONNECTED;
119-
case WL_CONNECT_FAILED:
120-
return AIO_NET_CONNECT_FAILED;
121-
case WL_IDLE_STATUS:
122-
return AIO_IDLE;
123-
default:
124-
return AIO_NET_DISCONNECTED;
77+
/**************************************************************************/
78+
/*!
79+
@brief Destructor for the Adafruit IO AirLift class.
80+
*/
81+
/**************************************************************************/
82+
~AdafruitIO_AIRLIFT()
83+
{
84+
if (_mqtt_client)
85+
delete _http_client;
86+
if (_http_client)
87+
delete _mqtt_client;
88+
if (_mqtt)
89+
delete _mqtt;
90+
if (_http)
91+
delete _http;
12592
}
126-
}
12793

128-
/*****************************************************************/
129-
/*!
130-
@brief Returns the type of network connection used by AdafruitIO.
131-
@return AIRLIFT
132-
*/
133-
/*****************************************************************/
134-
const char *connectionType() { return "AIRLIFT"; }
135-
136-
protected:
137-
const char *_ssid; /*!< WiFi network SSID. */
138-
const char *_pass; /*!< WiFi network password. */
139-
String _fv = "0.0.0"; /*!< nina-fw version, read from ESP32. */
140-
int _ssPin = -1; /*!< ESP32 slave-select pin. */
141-
int _ackPin = -1; /*!< ESP32 ACK pin. */
142-
int _rstPin = -1; /*!< ESP32 RESET pin. */
143-
int _gpio0Pin = -1; /*!< ESP32 GPIO0 pin. */
144-
145-
WiFiSSLClient *_http_client; /*!< Instance of HTTP client. */
146-
WiFiSSLClient *_mqtt_client; /*!< Instance of MQTT client. */
147-
148-
SPIClass *_wifi; /*!< Instance of WiFi. */
149-
150-
/**************************************************************************/
151-
/*!
152-
@brief Attempts to establish a WiFi connection with the wireless network,
153-
given _ssid and _pass from the AdafruitIO_AIRLIFT constructor.
154-
*/
155-
/**************************************************************************/
156-
void _connect() {
157-
if (strlen(_ssid) == 0) {
158-
_status = AIO_SSID_INVALID;
159-
} else {
160-
_disconnect();
161-
// setup ESP32 pins
162-
if (_ssPin != -1) {
163-
WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
94+
/********************************************************/
95+
/*!
96+
@brief Checks the version of an ESP32 module against
97+
NINAFWVER. Raises an error if the firmware needs to be
98+
upgraded.
99+
*/
100+
/********************************************************/
101+
void firmwareCheck()
102+
{
103+
_fv = WiFi.firmwareVersion();
104+
if (_fv < NINAFWVER)
105+
{
106+
AIO_DEBUG_PRINTLN("Please upgrade the firmware on the ESP module");
164107
}
108+
}
165109

166-
// check esp32 module version against NINAFWVER
167-
firmwareCheck();
168-
169-
// check for esp32 module
170-
if (WiFi.status() == WL_NO_MODULE) {
171-
AIO_DEBUG_PRINTLN("No ESP32 module detected!");
172-
return;
110+
/********************************************************/
111+
/*!
112+
@brief Returns the network status of an ESP32 module.
113+
@return aio_status_t
114+
*/
115+
/********************************************************/
116+
aio_status_t networkStatus()
117+
{
118+
switch (WiFi.status())
119+
{
120+
case WL_CONNECTED:
121+
return AIO_NET_CONNECTED;
122+
case WL_CONNECT_FAILED:
123+
return AIO_NET_CONNECT_FAILED;
124+
case WL_IDLE_STATUS:
125+
return AIO_IDLE;
126+
default:
127+
return AIO_NET_DISCONNECTED;
173128
}
129+
}
174130

175-
WiFi.begin(_ssid, _pass);
176-
_status = AIO_NET_DISCONNECTED;
131+
/*****************************************************************/
132+
/*!
133+
@brief Returns the type of network connection used by AdafruitIO.
134+
@return AIRLIFT
135+
*/
136+
/*****************************************************************/
137+
const char *connectionType()
138+
{
139+
return "AIRLIFT";
177140
}
178-
}
179141

180-
/**************************************************************************/
181-
/*!
182-
@brief Disconnect the wifi network.
183-
*/
184-
/**************************************************************************/
185-
void _disconnect() {
186-
WiFi.disconnect();
187-
delay(AIO_NET_DISCONNECT_WAIT);
142+
protected:
143+
const char *_ssid;
144+
const char *_pass;
145+
String _fv = "0.0.0";
146+
int _ssPin, _ackPin, _rstPin, _gpio0Pin = -1;
147+
148+
WiFiSSLClient *_http_client;
149+
WiFiSSLClient *_mqtt_client;
150+
151+
SPIClass *_wifi;
152+
153+
/**************************************************************************/
154+
/*!
155+
@brief Attempts to establish a WiFi connection with the wireless network,
156+
given _ssid and _pass from the AdafruitIO_AIRLIFT constructor.
157+
*/
158+
/**************************************************************************/
159+
void _connect()
160+
{
161+
if(strlen(_ssid) == 0) {
162+
_status = AIO_SSID_INVALID;
163+
} else {
164+
_disconnect();
165+
// setup ESP32 pins
166+
if (_ssPin != -1) {
167+
WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
168+
}
169+
170+
// check esp32 module version against NINAFWVER
171+
firmwareCheck();
172+
173+
// check for esp32 module
174+
if (WiFi.status() == WL_NO_MODULE)
175+
{
176+
AIO_DEBUG_PRINTLN("No ESP32 module detected!");
177+
return;
178+
}
179+
180+
WiFi.begin(_ssid, _pass);
181+
_status = AIO_NET_DISCONNECTED;
182+
}
188183
}
184+
185+
/**************************************************************************/
186+
/*!
187+
@brief Disconnect the wifi network.
188+
*/
189+
/**************************************************************************/
190+
void _disconnect()
191+
{
192+
WiFi.disconnect();
193+
delay(AIO_NET_DISCONNECT_WAIT);
194+
}
195+
189196
};
190197

191198
#endif // ADAFRUITIO_AIRLIFT_H

0 commit comments

Comments
 (0)