From b21d7637dafc37d5e5577c41fa40ef9465d12a0f Mon Sep 17 00:00:00 2001
From: brentru <brent@adafruit.com>
Date: Mon, 1 Apr 2024 12:43:56 -0400
Subject: [PATCH 1/3] add rp2040

---
 .github/workflows/githubci.yml |   3 +-
 README.md                      |   2 +-
 library.properties             |   4 +-
 src/AdafruitIO_WiFi.h          |   5 +
 src/util/AdafruitIO_Board.cpp  |   2 +
 src/wifi/AdafruitIO_RP2040.h   | 177 +++++++++++++++++++++++++++++++++
 6 files changed, 189 insertions(+), 4 deletions(-)
 create mode 100644 src/wifi/AdafruitIO_RP2040.h

diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml
index d5d74a8..a834dfc 100644
--- a/.github/workflows/githubci.yml
+++ b/.github/workflows/githubci.yml
@@ -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
     
diff --git a/README.md b/README.md
index 58a25fc..2ff1696 100644
--- a/README.md
+++ b/README.md
@@ -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
 
diff --git a/library.properties b/library.properties
index 1733e08..445bf59 100644
--- a/library.properties
+++ b/library.properties
@@ -1,9 +1,9 @@
 name=Adafruit IO Arduino
-version=4.2.9
+version=4.3.0
 author=Adafruit
 maintainer=Adafruit <adafruitio@adafruit.com>
 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=*
diff --git a/src/AdafruitIO_WiFi.h b/src/AdafruitIO_WiFi.h
index 4ab00c8..53335e1 100644
--- a/src/AdafruitIO_WiFi.h
+++ b/src/AdafruitIO_WiFi.h
@@ -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."
diff --git a/src/util/AdafruitIO_Board.cpp b/src/util/AdafruitIO_Board.cpp
index 402f98b..95554af 100644
--- a/src/util/AdafruitIO_Board.cpp
+++ b/src/util/AdafruitIO_Board.cpp
@@ -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
diff --git a/src/wifi/AdafruitIO_RP2040.h b/src/wifi/AdafruitIO_RP2040.h
new file mode 100644
index 0000000..10281ea
--- /dev/null
+++ b/src/wifi/AdafruitIO_RP2040.h
@@ -0,0 +1,177 @@
+/*!
+ * @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"
+      "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"; ///< 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 (WiFi.status() == WL_CONNECTED)
+      return;
+
+    if (strlen(_ssid) == 0) {
+      _status = AIO_SSID_INVALID;
+    } else {
+      _disconnect();
+      delay(5000);
+      WiFi.mode(WIFI_STA);
+      WiFi.setTimeout(20000);
+      WiFi.begin(_ssid, _pass);
+      // Wait setTimeout duration for a connection and check if connected every
+      // 5 seconds
+      for (int i = 0; i < 4; i++) {
+        delay(5000);
+        if (WiFi.status() == WL_CONNECTED) {
+          _status = AIO_NET_CONNECTED;
+          return;
+        }
+      }
+      _status = AIO_NET_DISCONNECTED;
+    }
+  }
+
+  /**************************************************************************/
+  /*!
+      @brief    Disconnects from the wifi network.
+  */
+  /**************************************************************************/
+  void _disconnect() {
+    WiFi.disconnect();
+    delay(AIO_NET_DISCONNECT_WAIT);
+  }
+};
+
+#endif // ADAFRUITIO_RP2040_H
+#endif // ARDUINO_ARCH_RP2040

From 7c3049e55b7b4428577932dba34de98815fc4d95 Mon Sep 17 00:00:00 2001
From: brentru <brent@adafruit.com>
Date: Mon, 1 Apr 2024 15:38:42 -0400
Subject: [PATCH 2/3] test works

---
 src/wifi/AdafruitIO_RP2040.h | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/wifi/AdafruitIO_RP2040.h b/src/wifi/AdafruitIO_RP2040.h
index 10281ea..8ca9118 100644
--- a/src/wifi/AdafruitIO_RP2040.h
+++ b/src/wifi/AdafruitIO_RP2040.h
@@ -137,29 +137,19 @@ class AdafruitIO_RP2040 : public AdafruitIO {
   */
   /**************************************************************************/
   void _connect() {
-
-    if (WiFi.status() == WL_CONNECTED)
-      return;
-
     if (strlen(_ssid) == 0) {
+      Serial.println("Invalid SSID!");
       _status = AIO_SSID_INVALID;
     } else {
       _disconnect();
-      delay(5000);
+      delay(10000);
       WiFi.mode(WIFI_STA);
       WiFi.setTimeout(20000);
       WiFi.begin(_ssid, _pass);
-      // Wait setTimeout duration for a connection and check if connected every
-      // 5 seconds
-      for (int i = 0; i < 4; i++) {
-        delay(5000);
-        if (WiFi.status() == WL_CONNECTED) {
-          _status = AIO_NET_CONNECTED;
-          return;
-        }
-      }
+      Serial.println("\nConnecting");
       _status = AIO_NET_DISCONNECTED;
     }
+    _mqtt_client->setCACert(_aio_root_ca_prod);
   }
 
   /**************************************************************************/

From a9a9c19531b6b47d7cf3a58a5d487689b2774ba8 Mon Sep 17 00:00:00 2001
From: brentru <brent@adafruit.com>
Date: Mon, 1 Apr 2024 15:39:43 -0400
Subject: [PATCH 3/3] add 2x skipfiles

---
 .../adafruitio_27_wifimanager/.picow_rp2040_tinyusb.test.skip    | 1 +
 .../.picow_rp2040_tinyusb.test.skip                              | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 examples/adafruitio_27_wifimanager/.picow_rp2040_tinyusb.test.skip
 create mode 100644 examples/adafruitio_28_wifimanager-custom-aio-parameters/.picow_rp2040_tinyusb.test.skip

diff --git a/examples/adafruitio_27_wifimanager/.picow_rp2040_tinyusb.test.skip b/examples/adafruitio_27_wifimanager/.picow_rp2040_tinyusb.test.skip
new file mode 100644
index 0000000..d3f5a12
--- /dev/null
+++ b/examples/adafruitio_27_wifimanager/.picow_rp2040_tinyusb.test.skip
@@ -0,0 +1 @@
+
diff --git a/examples/adafruitio_28_wifimanager-custom-aio-parameters/.picow_rp2040_tinyusb.test.skip b/examples/adafruitio_28_wifimanager-custom-aio-parameters/.picow_rp2040_tinyusb.test.skip
new file mode 100644
index 0000000..d3f5a12
--- /dev/null
+++ b/examples/adafruitio_28_wifimanager-custom-aio-parameters/.picow_rp2040_tinyusb.test.skip
@@ -0,0 +1 @@
+