Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RP2040/PicoW #171

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
fail-fast: false
matrix:
arduino-platform: ["esp8266", "esp32",
"pyportal", "metro_m4_airliftlite"]
"pyportal", "metro_m4_airliftlite",
"picow_rp2040_tinyusb"]

runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Adafruit IO Arduino
version=4.2.9
version=4.3.0
author=Adafruit
maintainer=Adafruit <[email protected]>
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
url=https://github.com/adafruit/Adafruit_IO_Arduino
architectures=*
Expand Down
5 changes: 5 additions & 0 deletions src/AdafruitIO_WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ typedef AdafruitIO_ESP8266 AdafruitIO_WiFi;
#include "wifi/AdafruitIO_WICED.h"
typedef AdafruitIO_WICED AdafruitIO_WiFi;

#elif defined(ARDUINO_ARCH_RP2040)

#include "wifi/AdafruitIO_RP2040.h"
typedef AdafruitIO_RP2040 AdafruitIO_WiFi;

#else

#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."
Expand Down
2 changes: 2 additions & 0 deletions src/util/AdafruitIO_Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const char AdafruitIO_Board::_type[] = "feather_wiced";
const char AdafruitIO_Board::_type[] = "esp32";
#elif defined(ESP8266)
const char AdafruitIO_Board::_type[] = "esp8266";
#elif defined(ARDUINO_ARCH_RP2040)
const char AdafruitIO_Board::_type[] = "rp2040";
#else
const char AdafruitIO_Board::_type[] = "unknown";
#endif
Expand Down
167 changes: 167 additions & 0 deletions src/wifi/AdafruitIO_RP2040.h
Original file line number Diff line number Diff line change
@@ -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 =
"-----BEGIN CERTIFICATE-----\n"
"MIIEjTCCA3WgAwIBAgIQDQd4KhM/xvmlcpbhMf/ReTANBgkqhkiG9w0BAQsFADBh\n"
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5j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
"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