Merge pull request #171 from brentru/master
Add support for RP2040/PicoW
This commit is contained in:
commit
04e52a3f2d
8 changed files with 181 additions and 4 deletions
3
.github/workflows/githubci.yml
vendored
3
.github/workflows/githubci.yml
vendored
|
|
@ -8,7 +8,8 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
arduino-platform: ["esp8266", "esp32",
|
arduino-platform: ["esp8266", "esp32",
|
||||||
"pyportal", "metro_m4_airliftlite"]
|
"pyportal", "metro_m4_airliftlite",
|
||||||
|
"picow_rp2040_tinyusb"]
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, ESP32, ESP32-S2, ESP32-S3, ESP32-C3, Airlift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing).
|
This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, ESP32, ESP32-S2, ESP32-S3, ESP32-C3, RP2040, Airlift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing).
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
name=Adafruit IO Arduino
|
name=Adafruit IO Arduino
|
||||||
version=4.2.9
|
version=4.3.0
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <adafruitio@adafruit.com>
|
maintainer=Adafruit <adafruitio@adafruit.com>
|
||||||
sentence=Arduino library to access Adafruit IO.
|
sentence=Arduino library to access Adafruit IO.
|
||||||
paragraph=Arduino library to access Adafruit IO using the Adafruit AirLift, ESP8266, ESP32, ESP32-S2, M0 WINC1500, WICED, MKR1000, Ethernet, or FONA hardware.
|
paragraph=Arduino library to access Adafruit IO using WiFi, ethernet, or cellular.
|
||||||
category=Communication
|
category=Communication
|
||||||
url=https://github.com/adafruit/Adafruit_IO_Arduino
|
url=https://github.com/adafruit/Adafruit_IO_Arduino
|
||||||
architectures=*
|
architectures=*
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,11 @@ typedef AdafruitIO_ESP8266 AdafruitIO_WiFi;
|
||||||
#include "wifi/AdafruitIO_WICED.h"
|
#include "wifi/AdafruitIO_WICED.h"
|
||||||
typedef AdafruitIO_WICED AdafruitIO_WiFi;
|
typedef AdafruitIO_WICED AdafruitIO_WiFi;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
|
||||||
|
#include "wifi/AdafruitIO_RP2040.h"
|
||||||
|
typedef AdafruitIO_RP2040 AdafruitIO_WiFi;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."
|
#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ const char AdafruitIO_Board::_type[] = "feather_wiced";
|
||||||
const char AdafruitIO_Board::_type[] = "esp32";
|
const char AdafruitIO_Board::_type[] = "esp32";
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
const char AdafruitIO_Board::_type[] = "esp8266";
|
const char AdafruitIO_Board::_type[] = "esp8266";
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
const char AdafruitIO_Board::_type[] = "rp2040";
|
||||||
#else
|
#else
|
||||||
const char AdafruitIO_Board::_type[] = "unknown";
|
const char AdafruitIO_Board::_type[] = "unknown";
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
167
src/wifi/AdafruitIO_RP2040.h
Normal file
167
src/wifi/AdafruitIO_RP2040.h
Normal file
|
|
@ -0,0 +1,167 @@
|
||||||
|
/*!
|
||||||
|
* @file AdafruitIO_RP2040.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Adafruit invests time and resources providing this open source code,
|
||||||
|
* please support Adafruit and open-source hardware by purchasing
|
||||||
|
* products from Adafruit!
|
||||||
|
*
|
||||||
|
* Copyright 2024 Brent Rubell for Adafruit Industries.
|
||||||
|
*
|
||||||
|
* MIT license, all text here must be included in any redistribution.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef ADAFRUITIO_RP2040_H
|
||||||
|
#define ADAFRUITIO_RP2040_H
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_RP2040
|
||||||
|
|
||||||
|
#include "AdafruitIO.h"
|
||||||
|
#include "Adafruit_MQTT.h"
|
||||||
|
#include "Adafruit_MQTT_Client.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Class that stores functions for interacting with the RP2040
|
||||||
|
WiFi Client
|
||||||
|
*/
|
||||||
|
/****************************************************************************/
|
||||||
|
class AdafruitIO_RP2040 : public AdafruitIO {
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Initializes the Adafruit IO class for RP2040 boards.
|
||||||
|
@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.
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
AdafruitIO_RP2040(const char *user, const char *key, const char *ssid,
|
||||||
|
const char *pass)
|
||||||
|
: AdafruitIO(user, key) {
|
||||||
|
_ssid = ssid;
|
||||||
|
_pass = pass;
|
||||||
|
_mqtt_client = new WiFiClientSecure;
|
||||||
|
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
|
||||||
|
_http_client = new WiFiClientSecure;
|
||||||
|
_http = new HttpClient(*_http_client, _host, _http_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************/
|
||||||
|
/*!
|
||||||
|
@brief Class dtor
|
||||||
|
*/
|
||||||
|
/*******************************/
|
||||||
|
~AdafruitIO_RP2040() {
|
||||||
|
if (_mqtt_client)
|
||||||
|
delete _http_client;
|
||||||
|
if (_http_client)
|
||||||
|
delete _mqtt_client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Returns the network status of the RP2040.
|
||||||
|
@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 RP2040
|
||||||
|
*/
|
||||||
|
/******************************************************************/
|
||||||
|
const char *connectionType() { return "RP2040"; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const char *_ssid; ///< WiFi network SSID
|
||||||
|
const char *_pass; ///< WiFi network password
|
||||||
|
|
||||||
|
WiFiClientSecure *_http_client; ///< HTTP client
|
||||||
|
WiFiClientSecure *_mqtt_client; ///< MQTT client
|
||||||
|
|
||||||
|
const char *_aio_root_ca_prod =
|
||||||
|
"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gYDVR0PAQH/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"; ///< Root certificate for io.adafruit.com
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Attempts to establish a WiFi connection with the wireless network,
|
||||||
|
given _ssid and _pass from the AdafruitIO_RP2040 constructor.
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void _connect() {
|
||||||
|
if (strlen(_ssid) == 0) {
|
||||||
|
Serial.println("Invalid SSID!");
|
||||||
|
_status = AIO_SSID_INVALID;
|
||||||
|
} else {
|
||||||
|
_disconnect();
|
||||||
|
delay(10000);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.setTimeout(20000);
|
||||||
|
WiFi.begin(_ssid, _pass);
|
||||||
|
Serial.println("\nConnecting");
|
||||||
|
_status = AIO_NET_DISCONNECTED;
|
||||||
|
}
|
||||||
|
_mqtt_client->setCACert(_aio_root_ca_prod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Disconnects from the wifi network.
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void _disconnect() {
|
||||||
|
WiFi.disconnect();
|
||||||
|
delay(AIO_NET_DISCONNECT_WAIT);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADAFRUITIO_RP2040_H
|
||||||
|
#endif // ARDUINO_ARCH_RP2040
|
||||||
Loading…
Reference in a new issue