Skip to content

Commit 2d25405

Browse files
brentrubrentru
authored andcommitted
add airlift function, away from wifi subclass
1 parent 3c611fd commit 2d25405

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

src/AdafruitIO_AIRLIFT.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2019 Adafruit Industries
7+
// Authors: Brent Rubell
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#if !defined(ARDUINO_SAMD_MKR1000) && defined(ARDUINO_ARCH_SAMD)
13+
14+
#include "AdafruitIO_AIRLIFT.h"
15+
16+
17+
AdafruitIO_AIRLIFT::AdafruitIO_AIRLIFT(const char *user, const char *key, const char *ssid, const char *pass):AdafruitIO(user, key)
18+
{
19+
_ssid = ssid;
20+
_pass = pass;
21+
_mqtt_client = new WiFiSSLClient;
22+
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
23+
_http_client = new WiFiSSLClient;
24+
_http = new HttpClient(*_http_client, _host, _http_port);
25+
}
26+
27+
AdafruitIO_AIRLIFT::~AdafruitIO_AIRLIFT()
28+
{
29+
if(_mqtt_client)
30+
delete _http_client;
31+
if(_http_client)
32+
delete _mqtt_client;
33+
if(_mqtt)
34+
delete _mqtt;
35+
if(_http)
36+
delete _http;
37+
}
38+
39+
40+
void AdafruitIO_AIRLIFT::_connect()
41+
{
42+
// for breakouts, check if the pins would be externally defined
43+
#ifdef BOARDEF
44+
WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
45+
#endif
46+
47+
// check esp32 module status
48+
if(WiFi.status() == WL_NO_MODULE){
49+
Serial.print(WiFi.status());
50+
}
51+
52+
WiFi.begin(_ssid, _pass);
53+
_status = AIO_NET_DISCONNECTED;
54+
55+
}
56+
57+
aio_status_t AdafruitIO_AIRLIFT::networkStatus()
58+
{
59+
switch(WiFi.status()) {
60+
case WL_CONNECTED:
61+
return AIO_NET_CONNECTED;
62+
case WL_CONNECT_FAILED:
63+
return AIO_NET_CONNECT_FAILED;
64+
case WL_IDLE_STATUS:
65+
return AIO_IDLE;
66+
default:
67+
return AIO_NET_DISCONNECTED;
68+
}
69+
}
70+
71+
const char* AdafruitIO_AIRLIFT::connectionType()
72+
{
73+
return "AIRLIFT";
74+
}
75+
76+
#endif // ARDUINO_ARCH_SAMD

src/AdafruitIO_AIRLIFT.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2019 Adafruit Industries
7+
// Authors: Brent Rubell
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#ifndef ADAFRUITIO_AIRLIFT_H
13+
#define ADAFRUITIO_AIRLIFT_H
14+
15+
#if !defined(ARDUINO_SAMD_MKR1000) && defined(ARDUINO_ARCH_SAMD)
16+
17+
#include "Arduino.h"
18+
#include "AdafruitIO.h"
19+
#include "WiFiNINA.h"
20+
#include "SPI.h"
21+
#include "Adafruit_MQTT.h"
22+
#include "Adafruit_MQTT_Client.h"
23+
24+
// Configure the pins used for the ESP32 connection
25+
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
26+
#define BOARDEF 1
27+
#define SPIWIFI SPI
28+
#define SPIWIFI_SS _airlift_ss // Chip select pin
29+
#define SPIWIFI_ACK _airlift_ack // a.k.a BUSY or READY pin
30+
#define ESP32_RESETN _airlift_rst // Reset pin
31+
#define ESP32_GPIO0 -1 // Not connected
32+
#endif
33+
34+
class AdafruitIO_AIRLIFT : public AdafruitIO {
35+
36+
public:
37+
AdafruitIO_AIRLIFT(const char *user, const char *key, const char *ssid, const char *pass);
38+
~AdafruitIO_AIRLIFT();
39+
40+
aio_status_t networkStatus();
41+
const char* connectionType();
42+
43+
protected:
44+
void _connect();
45+
const char *_ssid;
46+
const char *_pass;
47+
48+
WiFiSSLClient *_http_client;
49+
WiFiSSLClient *_mqtt_client;
50+
51+
};
52+
53+
#endif // ARDUINO_ARCH_SAMD
54+
55+
#endif // ADAFRUITIO_AIRLIFT_H

0 commit comments

Comments
 (0)