first commit
This commit is contained in:
207
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_AIRLIFT.h
Normal file
207
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_AIRLIFT.h
Normal file
@@ -0,0 +1,207 @@
|
||||
/*!
|
||||
* @file AdafruitIO_AIRLIFT.h
|
||||
*
|
||||
* This is part of Adafruit IO Arduino. It is designed specifically to work
|
||||
* with Adafruit's AirLift ESP32 Co-Processor.
|
||||
*
|
||||
* The ESP32 uses SPI to communicate. Three lines (CS, ACK, RST) are required
|
||||
* to communicate with the ESP32.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Brent Rubell for Adafruit Industries.
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
#ifndef ADAFRUITIO_AIRLIFT_H
|
||||
#define ADAFRUITIO_AIRLIFT_H
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
#include "WiFiNINA.h"
|
||||
|
||||
#define NINAFWVER \
|
||||
"1.0.0" /*!< nina-fw version compatible with this library. \
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/*!
|
||||
@brief Class that stores functions for interacting with AirLift Devices
|
||||
*/
|
||||
/****************************************************************************/
|
||||
class AdafruitIO_AIRLIFT : public AdafruitIO {
|
||||
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initializes the Adafruit IO class for AirLift devices.
|
||||
@param user
|
||||
A reference to the Adafruit IO user, shared by AdafruitIO.
|
||||
@param key
|
||||
A reference to the Adafruit IO Key, shared by AdafruitIO.
|
||||
@param ssid
|
||||
A reference to the WiFi network SSID.
|
||||
@param pass
|
||||
A reference to the WiFi network password.
|
||||
@param ssPin
|
||||
A reference to the ESP32_SS Pin.
|
||||
@param ackPin
|
||||
A reference to the ESP32_ACK Pin.
|
||||
@param rstPin
|
||||
A reference to the ESP32_RST Pin.
|
||||
@param gpio0Pin
|
||||
A reference to the gpio0Pin Pin.
|
||||
@param wifi
|
||||
A reference to a SPIClass
|
||||
*/
|
||||
/**************************************************************************/
|
||||
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) {
|
||||
_wifi = wifi;
|
||||
_ssPin = ssPin;
|
||||
_ackPin = ackPin;
|
||||
_rstPin = rstPin;
|
||||
_gpio0Pin = gpio0Pin;
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
_mqtt_client = new WiFiSSLClient;
|
||||
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
|
||||
_http_client = new WiFiSSLClient;
|
||||
_http = new HttpClient(*_http_client, _host, _http_port);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor for the Adafruit IO AirLift class.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
~AdafruitIO_AIRLIFT() {
|
||||
if (_mqtt_client)
|
||||
delete _http_client;
|
||||
if (_http_client)
|
||||
delete _mqtt_client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
if (_http)
|
||||
delete _http;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Allows setting of the AirLift RGB led from the
|
||||
Adafruit IO AirLift Class.
|
||||
@param r
|
||||
Red value, unsigned 8 bit value (0->255)
|
||||
@param g
|
||||
Green value, unsigned 8 bit value (0->255)
|
||||
@param b
|
||||
Blue value, unsigned 8 bit value (0->255)
|
||||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setLEDs(uint8_t r, uint8_t g, uint8_t b) { WiFi.setLEDs(r, g, b); }
|
||||
|
||||
/********************************************************/
|
||||
/*!
|
||||
@brief Checks the version of an ESP32 module against
|
||||
NINAFWVER. Raises an error if the firmware needs to be
|
||||
upgraded.
|
||||
*/
|
||||
/********************************************************/
|
||||
void firmwareCheck() {
|
||||
_fv = WiFi.firmwareVersion();
|
||||
if (_fv < NINAFWVER) {
|
||||
AIO_DEBUG_PRINTLN("Please upgrade the firmware on the ESP module");
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
/*!
|
||||
@brief Returns the network status of an ESP32 module.
|
||||
@return aio_status_t
|
||||
*/
|
||||
/********************************************************/
|
||||
aio_status_t networkStatus() {
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECTED:
|
||||
return AIO_NET_CONNECTED;
|
||||
case WL_CONNECT_FAILED:
|
||||
return AIO_NET_CONNECT_FAILED;
|
||||
case WL_IDLE_STATUS:
|
||||
return AIO_IDLE;
|
||||
default:
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/*!
|
||||
@brief Returns the type of network connection used by AdafruitIO.
|
||||
@return AIRLIFT
|
||||
*/
|
||||
/*****************************************************************/
|
||||
const char *connectionType() { return "AIRLIFT"; }
|
||||
|
||||
protected:
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
String _fv = "0.0.0";
|
||||
int _ssPin, _ackPin, _rstPin, _gpio0Pin = -1;
|
||||
|
||||
WiFiSSLClient *_http_client;
|
||||
WiFiSSLClient *_mqtt_client;
|
||||
|
||||
SPIClass *_wifi;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Attempts to establish a WiFi connection with the wireless network,
|
||||
given _ssid and _pass from the AdafruitIO_AIRLIFT constructor.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
// setup ESP32 pins
|
||||
if (_ssPin != -1) {
|
||||
WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
|
||||
}
|
||||
|
||||
// check esp32 module version against NINAFWVER
|
||||
firmwareCheck();
|
||||
|
||||
// disconnect from possible previous connection
|
||||
_disconnect();
|
||||
|
||||
// check for esp32 module
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
AIO_DEBUG_PRINTLN("No ESP32 module detected!");
|
||||
return;
|
||||
}
|
||||
|
||||
WiFi.begin(_ssid, _pass);
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the wifi network.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _disconnect() {
|
||||
WiFi.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_AIRLIFT_H
|
||||
73
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.cpp
Normal file
73
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*!
|
||||
* @file AdafruitIO_ESP32.cpp
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2021 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece, Brent Rubell
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
#include "AdafruitIO_ESP32.h"
|
||||
|
||||
AdafruitIO_ESP32::AdafruitIO_ESP32(const char *user, const char *key,
|
||||
const char *ssid, const char *pass)
|
||||
: AdafruitIO(user, key) {
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
_client = new WiFiClientSecure;
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
|
||||
AdafruitIO_ESP32::~AdafruitIO_ESP32() {
|
||||
if (_client)
|
||||
delete _client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
}
|
||||
|
||||
void AdafruitIO_ESP32::_connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
_disconnect();
|
||||
delay(100);
|
||||
WiFi.begin(_ssid, _pass);
|
||||
delay(100);
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
_client->setCACert(_aio_root_ca);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the wifi network.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_ESP32::_disconnect() {
|
||||
WiFi.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
|
||||
aio_status_t AdafruitIO_ESP32::networkStatus() {
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECTED:
|
||||
return AIO_NET_CONNECTED;
|
||||
case WL_CONNECT_FAILED:
|
||||
return AIO_NET_CONNECT_FAILED;
|
||||
case WL_IDLE_STATUS:
|
||||
return AIO_IDLE;
|
||||
default:
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
const char *AdafruitIO_ESP32::connectionType() { return "wifi"; }
|
||||
|
||||
#endif // ESP32
|
||||
78
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.h
Normal file
78
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*!
|
||||
* @file AdafruitIO_ESP32.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2021 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece, Brent Rubell
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_ESP32_H
|
||||
#define ADAFRUITIO_ESP32_H
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include "WiFiClientSecure.h"
|
||||
#include <WiFi.h>
|
||||
|
||||
class AdafruitIO_ESP32 : public AdafruitIO {
|
||||
|
||||
public:
|
||||
AdafruitIO_ESP32(const char *user, const char *key, const char *ssid,
|
||||
const char *pass);
|
||||
~AdafruitIO_ESP32();
|
||||
|
||||
aio_status_t networkStatus();
|
||||
const char *connectionType();
|
||||
|
||||
protected:
|
||||
void _connect();
|
||||
void _disconnect();
|
||||
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
|
||||
WiFiClientSecure *_client;
|
||||
|
||||
// io.adafruit.com root CA
|
||||
const char *_aio_root_ca =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
"MIIEjTCCA3WgAwIBAgIQDQd4KhM/xvmlcpbhMf/ReTANBgkqhkiG9w0BAQsFADBh\n"
|
||||
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
|
||||
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n"
|
||||
"MjAeFw0xNzExMDIxMjIzMzdaFw0yNzExMDIxMjIzMzdaMGAxCzAJBgNVBAYTAlVT\n"
|
||||
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n"
|
||||
"b20xHzAdBgNVBAMTFkdlb1RydXN0IFRMUyBSU0EgQ0EgRzEwggEiMA0GCSqGSIb3\n"
|
||||
"DQEBAQUAA4IBDwAwggEKAoIBAQC+F+jsvikKy/65LWEx/TMkCDIuWegh1Ngwvm4Q\n"
|
||||
"yISgP7oU5d79eoySG3vOhC3w/3jEMuipoH1fBtp7m0tTpsYbAhch4XA7rfuD6whU\n"
|
||||
"gajeErLVxoiWMPkC/DnUvbgi74BJmdBiuGHQSd7LwsuXpTEGG9fYXcbTVN5SATYq\n"
|
||||
"DfbexbYxTMwVJWoVb6lrBEgM3gBBqiiAiy800xu1Nq07JdCIQkBsNpFtZbIZhsDS\n"
|
||||
"fzlGWP4wEmBQ3O67c+ZXkFr2DcrXBEtHam80Gp2SNhou2U5U7UesDL/xgLK6/0d7\n"
|
||||
"6TnEVMSUVJkZ8VeZr+IUIlvoLrtjLbqugb0T3OYXW+CQU0kBAgMBAAGjggFAMIIB\n"
|
||||
"PDAdBgNVHQ4EFgQUlE/UXYvkpOKmgP792PkA76O+AlcwHwYDVR0jBBgwFoAUTiJU\n"
|
||||
"IBiV5uNu5g/6+rkS7QYXjzkwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsG\n"
|
||||
"AQUFBwMBBggrBgEFBQcDAjASBgNVHRMBAf8ECDAGAQH/AgEAMDQGCCsGAQUFBwEB\n"
|
||||
"BCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMEIGA1Ud\n"
|
||||
"HwQ7MDkwN6A1oDOGMWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEds\n"
|
||||
"b2JhbFJvb3RHMi5jcmwwPQYDVR0gBDYwNDAyBgRVHSAAMCowKAYIKwYBBQUHAgEW\n"
|
||||
"HGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwDQYJKoZIhvcNAQELBQADggEB\n"
|
||||
"AIIcBDqC6cWpyGUSXAjjAcYwsK4iiGF7KweG97i1RJz1kwZhRoo6orU1JtBYnjzB\n"
|
||||
"c4+/sXmnHJk3mlPyL1xuIAt9sMeC7+vreRIF5wFBC0MCN5sbHwhNN1JzKbifNeP5\n"
|
||||
"ozpZdQFmkCo+neBiKR6HqIA+LMTMCMMuv2khGGuPHmtDze4GmEGZtYLyF8EQpa5Y\n"
|
||||
"jPuV6k2Cr/N3XxFpT3hRpt/3usU/Zb9wfKPtWpoznZ4/44c1p9rzFcZYrWkj3A+7\n"
|
||||
"TNBJE0GmP2fhXhP1D/XVfIW/h0yCJGEiV9Glm/uGOa3DXHlmbAcxSyCRraG+ZBkA\n"
|
||||
"7h4SeM6Y8l/7MBRpPCz6l8Y=\n"
|
||||
"-----END CERTIFICATE-----\n";
|
||||
};
|
||||
|
||||
#endif // ESP32
|
||||
#endif // ADAFRUITIO_ESP32_H
|
||||
@@ -0,0 +1,79 @@
|
||||
/*!
|
||||
* @file AdafruitIO_ESP8266.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
#include "AdafruitIO_ESP8266.h"
|
||||
|
||||
AdafruitIO_ESP8266::AdafruitIO_ESP8266(const char *user, const char *key,
|
||||
const char *ssid, const char *pass)
|
||||
: AdafruitIO(user, key) {
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
// Uncomment the following lines and remove the existing WiFiClient and MQTT
|
||||
// client constructors to use Secure MQTT with ESP8266.
|
||||
// _client = new WiFiClientSecure;
|
||||
// _client->setFingerprint(AIO_SSL_FINGERPRINT);
|
||||
// _mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
|
||||
_client = new WiFiClient;
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, 1883);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
|
||||
AdafruitIO_ESP8266::~AdafruitIO_ESP8266() {
|
||||
if (_client)
|
||||
delete _client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
}
|
||||
|
||||
void AdafruitIO_ESP8266::_connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
_disconnect();
|
||||
delay(100);
|
||||
WiFi.begin(_ssid, _pass);
|
||||
delay(100);
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the wifi network.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_ESP8266::_disconnect() {
|
||||
WiFi.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
|
||||
aio_status_t AdafruitIO_ESP8266::networkStatus() {
|
||||
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECTED:
|
||||
return AIO_NET_CONNECTED;
|
||||
case WL_CONNECT_FAILED:
|
||||
return AIO_NET_CONNECT_FAILED;
|
||||
case WL_IDLE_STATUS:
|
||||
return AIO_IDLE;
|
||||
default:
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
const char *AdafruitIO_ESP8266::connectionType() { return "wifi"; }
|
||||
|
||||
#endif // ESP8266
|
||||
60
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP8266.h
Normal file
60
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP8266.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*!
|
||||
* @file AdafruitIO_ESP8266.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_ESP8266_H
|
||||
#define ADAFRUITIO_ESP8266_H
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include "ESP8266WiFi.h"
|
||||
/* NOTE - Projects that require "Secure MQTT" (TLS/SSL) also require a new
|
||||
* SSL certificate every year. If adding Secure MQTT to your ESP8266 project is
|
||||
* important - please switch to using the modern ESP32 (and related models)
|
||||
* instead of the ESP8266 to avoid updating the SSL fingerprint every year.
|
||||
*
|
||||
* If you've read through this and still want to use "Secure MQTT" with your
|
||||
* ESP8266 project, we've left the "WiFiClientSecure" lines commented out. To
|
||||
* use them, uncomment the commented out lines within `AdafruitIO_ESP8266.h` and
|
||||
* `AdafruitIO_ESP8266.cpp` and recompile the library.
|
||||
*/
|
||||
// #include "WiFiClientSecure.h"
|
||||
|
||||
class AdafruitIO_ESP8266 : public AdafruitIO {
|
||||
|
||||
public:
|
||||
AdafruitIO_ESP8266(const char *user, const char *key, const char *ssid,
|
||||
const char *pass);
|
||||
~AdafruitIO_ESP8266();
|
||||
|
||||
aio_status_t networkStatus();
|
||||
const char *connectionType();
|
||||
|
||||
protected:
|
||||
void _connect();
|
||||
void _disconnect();
|
||||
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
WiFiClient *_client;
|
||||
// Uncomment the following line, and remove the line above, to use
|
||||
// secure MQTT with ESP8266.
|
||||
// WiFiClientSecure *_client;
|
||||
};
|
||||
|
||||
#endif // ESP8266
|
||||
#endif // ADAFRUITIO_ESP8266_H
|
||||
@@ -0,0 +1,77 @@
|
||||
/*!
|
||||
* @file AdafruitIO_MKR1000.cpp
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_SAMD_MKR1000)
|
||||
|
||||
#include "AdafruitIO_MKR1000.h"
|
||||
|
||||
AdafruitIO_MKR1000::AdafruitIO_MKR1000(const char *user, const char *key,
|
||||
const char *ssid, const char *pass)
|
||||
: AdafruitIO(user, key) {
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
_client = new WiFiSSLClient;
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
|
||||
AdafruitIO_MKR1000::~AdafruitIO_MKR1000() {
|
||||
if (_client)
|
||||
delete _client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
}
|
||||
|
||||
void AdafruitIO_MKR1000::_connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
// no shield? bail
|
||||
if (WiFi.status() == WL_NO_SHIELD)
|
||||
return;
|
||||
|
||||
_disconnect();
|
||||
|
||||
WiFi.begin(_ssid, _pass);
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the wifi network.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_MKR1000::_disconnect() {
|
||||
WiFi.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
|
||||
aio_status_t AdafruitIO_MKR1000::networkStatus() {
|
||||
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECTED:
|
||||
return AIO_NET_CONNECTED;
|
||||
case WL_CONNECT_FAILED:
|
||||
return AIO_NET_CONNECT_FAILED;
|
||||
case WL_IDLE_STATUS:
|
||||
return AIO_IDLE;
|
||||
default:
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
const char *AdafruitIO_MKR1000::connectionType() { return "wifi"; }
|
||||
|
||||
#endif // ARDUINO_ARCH_SAMD
|
||||
50
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_MKR1000.h
Normal file
50
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_MKR1000.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*!
|
||||
* @file AdafruitIO_MKR1000.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_MKR1000_H
|
||||
#define ADAFRUITIO_MKR1000_H
|
||||
|
||||
#if defined(ARDUINO_SAMD_MKR1000)
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
#include "WiFi101.h"
|
||||
#include "WiFiSSLClient.h"
|
||||
|
||||
class AdafruitIO_MKR1000 : public AdafruitIO {
|
||||
|
||||
public:
|
||||
AdafruitIO_MKR1000(const char *user, const char *key, const char *ssid,
|
||||
const char *pass);
|
||||
~AdafruitIO_MKR1000();
|
||||
|
||||
aio_status_t networkStatus();
|
||||
const char *connectionType();
|
||||
|
||||
protected:
|
||||
void _connect();
|
||||
void _disconnect();
|
||||
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
|
||||
WiFiSSLClient *_client;
|
||||
};
|
||||
|
||||
#endif // ARDUINO_ARCH_SAMD
|
||||
|
||||
#endif // ADAFRUITIO_MKR1000_H
|
||||
83
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_MKR1010.h
Normal file
83
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_MKR1010.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*!
|
||||
* @file AdafruitIO_MKR1010.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: David Goldstein, Morgan Winters
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_MKR1010_H
|
||||
#define ADAFRUITIO_MKR1010_H
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
#include "WiFiNINA.h"
|
||||
#include "WiFiSSLClient.h"
|
||||
|
||||
class AdafruitIO_MKR1010 : public AdafruitIO {
|
||||
|
||||
public:
|
||||
AdafruitIO_MKR1010(const char *user, const char *key, const char *ssid,
|
||||
const char *pass)
|
||||
: AdafruitIO(user, key) {
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
_client = new WiFiSSLClient;
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
~AdafruitIO_MKR1010() {
|
||||
if (_client)
|
||||
delete _client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
}
|
||||
|
||||
aio_status_t networkStatus() {
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECTED:
|
||||
return AIO_NET_CONNECTED;
|
||||
case WL_CONNECT_FAILED:
|
||||
return AIO_NET_CONNECT_FAILED;
|
||||
case WL_IDLE_STATUS:
|
||||
return AIO_IDLE;
|
||||
default:
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
const char *connectionType() { return "wifi"; }
|
||||
|
||||
protected:
|
||||
void _connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
_disconnect();
|
||||
|
||||
WiFi.begin(_ssid, _pass);
|
||||
_status = networkStatus();
|
||||
}
|
||||
}
|
||||
|
||||
void _disconnect() {
|
||||
WiFi.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
|
||||
WiFiSSLClient *_client;
|
||||
};
|
||||
|
||||
#endif ADAFRUITIO_MKR1010_H
|
||||
70
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_WICED.cpp
Normal file
70
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_WICED.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*!
|
||||
* @file AdafruitIO_WICED.cpp
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_STM32_FEATHER
|
||||
|
||||
#include "AdafruitIO_WICED.h"
|
||||
|
||||
AdafruitIO_WICED::AdafruitIO_WICED(const char *user, const char *key,
|
||||
const char *ssid, const char *pass)
|
||||
: AdafruitIO(user, key) {
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
_client = new AdafruitIO_WICED_SSL;
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
|
||||
AdafruitIO_WICED::~AdafruitIO_WICED() {
|
||||
if (_client)
|
||||
delete _client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
}
|
||||
|
||||
void AdafruitIO_WICED::_connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
_disconnect();
|
||||
Feather.connect(_ssid, _pass);
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the wifi network.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_WICED::_disconnect() {
|
||||
Feather.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
|
||||
aio_status_t AdafruitIO_WICED::networkStatus() {
|
||||
if (Feather.connected())
|
||||
return AIO_NET_CONNECTED;
|
||||
|
||||
// if granular status is needed, we can
|
||||
// check Feather.errno() codes:
|
||||
// https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi/constants#err-t
|
||||
// for now we will try connecting again and return disconnected status
|
||||
Feather.connect(_ssid, _pass);
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
|
||||
const char *AdafruitIO_WICED::connectionType() { return "wifi"; }
|
||||
|
||||
#endif // ARDUINO_STM32_FEATHER
|
||||
47
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_WICED.h
Normal file
47
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_WICED.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*!
|
||||
* @file AdafruitIO_WICED.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_WICED_H
|
||||
#define ADAFRUITIO_WICED_H
|
||||
|
||||
#ifdef ARDUINO_STM32_FEATHER
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "AdafruitIO_WICED_SSL.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include <adafruit_feather.h>
|
||||
|
||||
class AdafruitIO_WICED : public AdafruitIO {
|
||||
|
||||
public:
|
||||
AdafruitIO_WICED(const char *user, const char *key, const char *ssid,
|
||||
const char *pass);
|
||||
~AdafruitIO_WICED();
|
||||
|
||||
aio_status_t networkStatus();
|
||||
const char *connectionType();
|
||||
|
||||
protected:
|
||||
void _connect();
|
||||
void _disconnect();
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
AdafruitIO_WICED_SSL *_client;
|
||||
};
|
||||
|
||||
#endif // ARDUINO_STM32_FEATHER
|
||||
|
||||
#endif // ADAFRUITIO_WICED_H
|
||||
@@ -0,0 +1,34 @@
|
||||
/*!
|
||||
* @file AdafruitIO_WICED_SSL.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_WICED_SSL_H
|
||||
#define ADAFRUITIO_WICED_SSL_H
|
||||
|
||||
#ifdef ARDUINO_STM32_FEATHER
|
||||
|
||||
#include <adafruit_feather.h>
|
||||
|
||||
class AdafruitIO_WICED_SSL : public AdafruitTCP {
|
||||
|
||||
public:
|
||||
AdafruitIO_WICED_SSL() : AdafruitTCP() {}
|
||||
|
||||
int connect(const char *host, uint16_t port) {
|
||||
return connectSSL(host, port);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ARDUINO_STM32_FEATHER
|
||||
|
||||
#endif // ADAFRUITIO_WICED_H
|
||||
159
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_WINC1500.h
Normal file
159
libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_WINC1500.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/*!
|
||||
* @file AdafruitIO_WINC1500.h
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUITIO_WINC1500_H
|
||||
#define ADAFRUITIO_WINC1500_H
|
||||
|
||||
#if !defined(ARDUINO_SAMD_MKR1000) && defined(ARDUINO_ARCH_SAMD) && \
|
||||
!defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) && !defined(ADAFRUIT_PYPORTAL)
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
#include "WiFi101.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with adafruit.io (AIO) using WINC1500
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_WINC1500 : public AdafruitIO {
|
||||
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiate the object.
|
||||
@param user
|
||||
A pointer to the AIO user name.
|
||||
@param key
|
||||
A pointer to the AIO key for the user.
|
||||
@param ssid
|
||||
A pointer to the SSID for the wifi.
|
||||
@param pass
|
||||
A pointer to the password for the wifi.
|
||||
@param winc_cs
|
||||
The cs pin number.
|
||||
@param winc_irq
|
||||
The irq pin number.
|
||||
@param winc_rst
|
||||
The rst pin number.
|
||||
@param winc_en
|
||||
The en pin number.
|
||||
@return none
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_WINC1500(const char *user, const char *key, const char *ssid,
|
||||
const char *pass, int winc_cs = 8, int winc_irq = 7,
|
||||
int winc_rst = 4, int winc_en = 2)
|
||||
: AdafruitIO(user, key) {
|
||||
_winc_cs = winc_cs;
|
||||
_winc_irq = winc_irq;
|
||||
_winc_rst = winc_rst;
|
||||
_winc_en = winc_en;
|
||||
_ssid = ssid;
|
||||
_pass = pass;
|
||||
_mqtt_client = new WiFiSSLClient;
|
||||
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
|
||||
_http_client = new WiFiSSLClient;
|
||||
_http = new HttpClient(*_http_client, _host, _http_port);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor to end the object.
|
||||
@return none
|
||||
*/
|
||||
/**************************************************************************/
|
||||
~AdafruitIO_WINC1500() {
|
||||
if (_mqtt_client)
|
||||
delete _http_client;
|
||||
if (_http_client)
|
||||
delete _mqtt_client;
|
||||
if (_mqtt)
|
||||
delete _mqtt;
|
||||
if (_http)
|
||||
delete _http;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Network status check.
|
||||
@return An AIO network status value. Lower values represent poorer
|
||||
connection status.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aio_status_t networkStatus() {
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECTED:
|
||||
return AIO_NET_CONNECTED;
|
||||
case WL_CONNECT_FAILED:
|
||||
return AIO_NET_CONNECT_FAILED;
|
||||
case WL_IDLE_STATUS:
|
||||
return AIO_IDLE;
|
||||
default:
|
||||
return AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
const char *connectionType() { return "winc1500"; }
|
||||
|
||||
protected:
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
int _winc_cs, _winc_irq, _winc_rst, _winc_en = 0;
|
||||
|
||||
WiFiSSLClient *_http_client;
|
||||
WiFiSSLClient *_mqtt_client;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Connect the wifi network.
|
||||
@return none
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _connect() {
|
||||
if (strlen(_ssid) == 0) {
|
||||
_status = AIO_SSID_INVALID;
|
||||
} else {
|
||||
_disconnect();
|
||||
WiFi.setPins(_winc_cs, _winc_irq, _winc_rst, _winc_en); //
|
||||
|
||||
// no shield? bail
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
AIO_DEBUG_PRINTLN("No WINC1500 Module Detected!");
|
||||
return;
|
||||
}
|
||||
|
||||
WiFi.begin(_ssid, _pass);
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the wifi network.
|
||||
@return none
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _disconnect() {
|
||||
WiFi.disconnect();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ARDUINO_ARCH_SAMD
|
||||
|
||||
#endif // ADAFRUITIO_WINC1500_H
|
||||
Reference in New Issue
Block a user