-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from brentru/master
Add support for RP2040/PicoW
- Loading branch information
Showing
8 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/adafruitio_27_wifimanager/.picow_rp2040_tinyusb.test.skip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
1 change: 1 addition & 0 deletions
1
examples/adafruitio_28_wifimanager-custom-aio-parameters/.picow_rp2040_tinyusb.test.skip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" | ||
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n" | ||
"MjAeFw0xNzExMDIxMjIzMzdaFw0yNzExMDIxMj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Oi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwDQYJKoZIhvcNAQELBQADggEB\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 |