Skip to content

Commit 04e52a3

Browse files
authored
Merge pull request #171 from brentru/master
Add support for RP2040/PicoW
2 parents 7f04b63 + a9a9c19 commit 04e52a3

File tree

8 files changed

+181
-4
lines changed

8 files changed

+181
-4
lines changed

.github/workflows/githubci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ jobs:
88
fail-fast: false
99
matrix:
1010
arduino-platform: ["esp8266", "esp32",
11-
"pyportal", "metro_m4_airliftlite"]
11+
"pyportal", "metro_m4_airliftlite",
12+
"picow_rp2040_tinyusb"]
1213

1314
runs-on: ubuntu-latest
1415

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
![AIOArduino](https://cdn-learn.adafruit.com/assets/assets/000/057/496/original/adafruit_io_AIOA.png?1531335660)
88

9-
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).
9+
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).
1010

1111
## Documentation
1212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

library.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Adafruit IO Arduino
2-
version=4.2.9
2+
version=4.3.0
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino library to access Adafruit IO.
6-
paragraph=Arduino library to access Adafruit IO using the Adafruit AirLift, ESP8266, ESP32, ESP32-S2, M0 WINC1500, WICED, MKR1000, Ethernet, or FONA hardware.
6+
paragraph=Arduino library to access Adafruit IO using WiFi, ethernet, or cellular.
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_IO_Arduino
99
architectures=*

src/AdafruitIO_WiFi.h

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ typedef AdafruitIO_ESP8266 AdafruitIO_WiFi;
5151
#include "wifi/AdafruitIO_WICED.h"
5252
typedef AdafruitIO_WICED AdafruitIO_WiFi;
5353

54+
#elif defined(ARDUINO_ARCH_RP2040)
55+
56+
#include "wifi/AdafruitIO_RP2040.h"
57+
typedef AdafruitIO_RP2040 AdafruitIO_WiFi;
58+
5459
#else
5560

5661
#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."

src/util/AdafruitIO_Board.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const char AdafruitIO_Board::_type[] = "feather_wiced";
2929
const char AdafruitIO_Board::_type[] = "esp32";
3030
#elif defined(ESP8266)
3131
const char AdafruitIO_Board::_type[] = "esp8266";
32+
#elif defined(ARDUINO_ARCH_RP2040)
33+
const char AdafruitIO_Board::_type[] = "rp2040";
3234
#else
3335
const char AdafruitIO_Board::_type[] = "unknown";
3436
#endif

src/wifi/AdafruitIO_RP2040.h

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*!
2+
* @file AdafruitIO_RP2040.h
3+
*
4+
*
5+
* Adafruit invests time and resources providing this open source code,
6+
* please support Adafruit and open-source hardware by purchasing
7+
* products from Adafruit!
8+
*
9+
* Copyright 2024 Brent Rubell for Adafruit Industries.
10+
*
11+
* MIT license, all text here must be included in any redistribution.
12+
*
13+
*/
14+
#ifndef ADAFRUITIO_RP2040_H
15+
#define ADAFRUITIO_RP2040_H
16+
17+
#ifdef ARDUINO_ARCH_RP2040
18+
19+
#include "AdafruitIO.h"
20+
#include "Adafruit_MQTT.h"
21+
#include "Adafruit_MQTT_Client.h"
22+
#include "Arduino.h"
23+
#include <WiFiClientSecure.h>
24+
25+
/****************************************************************************/
26+
/*!
27+
@brief Class that stores functions for interacting with the RP2040
28+
WiFi Client
29+
*/
30+
/****************************************************************************/
31+
class AdafruitIO_RP2040 : public AdafruitIO {
32+
33+
public:
34+
/**************************************************************************/
35+
/*!
36+
@brief Initializes the Adafruit IO class for RP2040 boards.
37+
@param user
38+
A reference to the Adafruit IO user, shared by AdafruitIO.
39+
@param key
40+
A reference to the Adafruit IO Key, shared by AdafruitIO.
41+
@param ssid
42+
A reference to the WiFi network SSID.
43+
@param pass
44+
A reference to the WiFi network password.
45+
*/
46+
/**************************************************************************/
47+
AdafruitIO_RP2040(const char *user, const char *key, const char *ssid,
48+
const char *pass)
49+
: AdafruitIO(user, key) {
50+
_ssid = ssid;
51+
_pass = pass;
52+
_mqtt_client = new WiFiClientSecure;
53+
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
54+
_http_client = new WiFiClientSecure;
55+
_http = new HttpClient(*_http_client, _host, _http_port);
56+
}
57+
58+
/*******************************/
59+
/*!
60+
@brief Class dtor
61+
*/
62+
/*******************************/
63+
~AdafruitIO_RP2040() {
64+
if (_mqtt_client)
65+
delete _http_client;
66+
if (_http_client)
67+
delete _mqtt_client;
68+
}
69+
70+
/********************************************************/
71+
/*!
72+
@brief Returns the network status of the RP2040.
73+
@return aio_status_t
74+
*/
75+
/********************************************************/
76+
aio_status_t networkStatus() {
77+
switch (WiFi.status()) {
78+
case WL_CONNECTED:
79+
return AIO_NET_CONNECTED;
80+
case WL_CONNECT_FAILED:
81+
return AIO_NET_CONNECT_FAILED;
82+
case WL_IDLE_STATUS:
83+
return AIO_IDLE;
84+
default:
85+
return AIO_NET_DISCONNECTED;
86+
}
87+
}
88+
89+
/******************************************************************/
90+
/*!
91+
@brief Returns the type of network connection used by AdafruitIO.
92+
@return RP2040
93+
*/
94+
/******************************************************************/
95+
const char *connectionType() { return "RP2040"; }
96+
97+
protected:
98+
const char *_ssid; ///< WiFi network SSID
99+
const char *_pass; ///< WiFi network password
100+
101+
WiFiClientSecure *_http_client; ///< HTTP client
102+
WiFiClientSecure *_mqtt_client; ///< MQTT client
103+
104+
const char *_aio_root_ca_prod =
105+
"-----BEGIN CERTIFICATE-----\n"
106+
"MIIEjTCCA3WgAwIBAgIQDQd4KhM/xvmlcpbhMf/ReTANBgkqhkiG9w0BAQsFADBh\n"
107+
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
108+
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n"
109+
"MjAeFw0xNzExMDIxMjIzMzdaFw0yNzExMDIxMjIzMzdaMGAxCzAJBgNVBAYTAlVT\n"
110+
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n"
111+
"b20xHzAdBgNVBAMTFkdlb1RydXN0IFRMUyBSU0EgQ0EgRzEwggEiMA0GCSqGSIb3\n"
112+
"DQEBAQUAA4IBDwAwggEKAoIBAQC+F+jsvikKy/65LWEx/TMkCDIuWegh1Ngwvm4Q\n"
113+
"yISgP7oU5d79eoySG3vOhC3w/3jEMuipoH1fBtp7m0tTpsYbAhch4XA7rfuD6whU\n"
114+
"gajeErLVxoiWMPkC/DnUvbgi74BJmdBiuGHQSd7LwsuXpTEGG9fYXcbTVN5SATYq\n"
115+
"DfbexbYxTMwVJWoVb6lrBEgM3gBBqiiAiy800xu1Nq07JdCIQkBsNpFtZbIZhsDS\n"
116+
"fzlGWP4wEmBQ3O67c+ZXkFr2DcrXBEtHam80Gp2SNhou2U5U7UesDL/xgLK6/0d7\n"
117+
"6TnEVMSUVJkZ8VeZr+IUIlvoLrtjLbqugb0T3OYXW+CQU0kBAgMBAAGjggFAMIIB\n"
118+
"PDAdBgNVHQ4EFgQUlE/UXYvkpOKmgP792PkA76O+AlcwHwYDVR0jBBgwFoAUTiJU\n"
119+
"IBiV5uNu5g/6+rkS7QYXjzkwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsG\n"
120+
"AQUFBwMBBggrBgEFBQcDAjASBgNVHRMBAf8ECDAGAQH/AgEAMDQGCCsGAQUFBwEB\n"
121+
"BCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMEIGA1Ud\n"
122+
"HwQ7MDkwN6A1oDOGMWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEds\n"
123+
"b2JhbFJvb3RHMi5jcmwwPQYDVR0gBDYwNDAyBgRVHSAAMCowKAYIKwYBBQUHAgEW\n"
124+
"HGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwDQYJKoZIhvcNAQELBQADggEB\n"
125+
"AIIcBDqC6cWpyGUSXAjjAcYwsK4iiGF7KweG97i1RJz1kwZhRoo6orU1JtBYnjzB\n"
126+
"c4+/sXmnHJk3mlPyL1xuIAt9sMeC7+vreRIF5wFBC0MCN5sbHwhNN1JzKbifNeP5\n"
127+
"ozpZdQFmkCo+neBiKR6HqIA+LMTMCMMuv2khGGuPHmtDze4GmEGZtYLyF8EQpa5Y\n"
128+
"jPuV6k2Cr/N3XxFpT3hRpt/3usU/Zb9wfKPtWpoznZ4/44c1p9rzFcZYrWkj3A+7\n"
129+
"TNBJE0GmP2fhXhP1D/XVfIW/h0yCJGEiV9Glm/uGOa3DXHlmbAcxSyCRraG+ZBkA\n"
130+
"7h4SeM6Y8l/7MBRpPCz6l8Y=\n"
131+
"-----END CERTIFICATE-----\n"; ///< Root certificate for io.adafruit.com
132+
133+
/**************************************************************************/
134+
/*!
135+
@brief Attempts to establish a WiFi connection with the wireless network,
136+
given _ssid and _pass from the AdafruitIO_RP2040 constructor.
137+
*/
138+
/**************************************************************************/
139+
void _connect() {
140+
if (strlen(_ssid) == 0) {
141+
Serial.println("Invalid SSID!");
142+
_status = AIO_SSID_INVALID;
143+
} else {
144+
_disconnect();
145+
delay(10000);
146+
WiFi.mode(WIFI_STA);
147+
WiFi.setTimeout(20000);
148+
WiFi.begin(_ssid, _pass);
149+
Serial.println("\nConnecting");
150+
_status = AIO_NET_DISCONNECTED;
151+
}
152+
_mqtt_client->setCACert(_aio_root_ca_prod);
153+
}
154+
155+
/**************************************************************************/
156+
/*!
157+
@brief Disconnects from the wifi network.
158+
*/
159+
/**************************************************************************/
160+
void _disconnect() {
161+
WiFi.disconnect();
162+
delay(AIO_NET_DISCONNECT_WAIT);
163+
}
164+
};
165+
166+
#endif // ADAFRUITIO_RP2040_H
167+
#endif // ARDUINO_ARCH_RP2040

0 commit comments

Comments
 (0)