Skip to content

Commit e38bc30

Browse files
authored
Merge pull request #176 from brentru/add-ard-uno-r4
Add compatibility for Arduino R4 WiFi and Minima
2 parents 1f87e56 + cc23ab0 commit e38bc30

File tree

3 files changed

+165
-1
lines changed

3 files changed

+165
-1
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit IO Arduino
2-
version=4.3.2
2+
version=4.3.3
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino library to access Adafruit IO.

src/AdafruitIO_WiFi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ typedef AdafruitIO_WICED AdafruitIO_WiFi;
5656
#include "wifi/AdafruitIO_RP2040.h"
5757
typedef AdafruitIO_RP2040 AdafruitIO_WiFi;
5858

59+
#elif defined(ARDUINO_UNOWIFIR4) || defined(ARDUINO_MINIMA)
60+
61+
#include "wifi/AdafruitIO_Arduino_RenesasUno.h"
62+
typedef AdafruitIO_Arduino_RenesasUno AdafruitIO_WiFi;
63+
5964
#else
6065

6166
#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*!
2+
* @file AdafruitIO_Arduino_RenesasUno.h
3+
*
4+
* This is part of Adafruit IO Arduino. It is designed specifically to work
5+
* with Arduino Renesas Uno WiFi Rev 4 and Arduino Minima.
6+
*
7+
* Adafruit invests time and resources providing this open source code,
8+
* please support Adafruit and open-source hardware by purchasing
9+
* products from Adafruit!
10+
*
11+
* Written by Brent Rubell for Adafruit Industries, 2025
12+
*
13+
* MIT license, all text here must be included in any redistribution.
14+
*
15+
*/
16+
#ifndef ADAFRUITIO_RENESAS_UNO_H
17+
#define ADAFRUITIO_RENESAS_UNO_H
18+
19+
#include "AdafruitIO.h"
20+
#include "Adafruit_MQTT.h"
21+
#include "Adafruit_MQTT_Client.h"
22+
#include "Arduino.h"
23+
#include "SPI.h"
24+
#include "WiFiS3.h"
25+
26+
/****************************************************************************/
27+
/*!
28+
@brief Class that stores functions for interacting with Uno R4 Devices
29+
*/
30+
/****************************************************************************/
31+
class AdafruitIO_Arduino_RenesasUno : public AdafruitIO {
32+
33+
public:
34+
/**************************************************************************/
35+
/*!
36+
@brief Initializes the Adafruit IO class for Uno R4 devices.
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_Arduino_RenesasUno(const char *user, const char *key,
48+
const char *ssid, const char *pass)
49+
: AdafruitIO(user, key) {
50+
_ssid = ssid;
51+
_pass = pass;
52+
_mqtt_client = new WiFiSSLClient;
53+
_mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
54+
_http_client = new WiFiSSLClient;
55+
_http = new HttpClient(*_http_client, _host, _http_port);
56+
}
57+
58+
/**************************************************************************/
59+
/*!
60+
@brief Destructor for the Adafruit IO AirLift class.
61+
*/
62+
/**************************************************************************/
63+
~AdafruitIO_Arduino_RenesasUno() {
64+
if (_mqtt_client)
65+
delete _http_client;
66+
if (_http_client)
67+
delete _mqtt_client;
68+
if (_mqtt)
69+
delete _mqtt;
70+
if (_http)
71+
delete _http;
72+
}
73+
74+
/********************************************************/
75+
/*!
76+
@brief Returns the network status of an ESP32 module.
77+
@return aio_status_t
78+
*/
79+
/********************************************************/
80+
aio_status_t networkStatus() {
81+
switch (WiFi.status()) {
82+
case WL_CONNECTED:
83+
return AIO_NET_CONNECTED;
84+
case WL_CONNECT_FAILED:
85+
return AIO_NET_CONNECT_FAILED;
86+
case WL_CONNECTION_LOST:
87+
return AIO_NET_CONNECT_FAILED;
88+
case WL_DISCONNECTED:
89+
return AIO_NET_DISCONNECTED;
90+
case WL_NO_MODULE:
91+
return AIO_NET_DISCONNECTED;
92+
case WL_IDLE_STATUS:
93+
return AIO_IDLE;
94+
default:
95+
return AIO_NET_DISCONNECTED;
96+
}
97+
}
98+
99+
/*****************************************************************/
100+
/*!
101+
@brief Returns the type of network connection used by AdafruitIO.
102+
@return RENESASUNOR4
103+
*/
104+
/*****************************************************************/
105+
const char *connectionType() { return "RENESASUNOR4"; }
106+
107+
protected:
108+
const char *_ssid;
109+
const char *_pass;
110+
WiFiSSLClient *_http_client;
111+
WiFiSSLClient *_mqtt_client;
112+
113+
/**************************************************************************/
114+
/*!
115+
@brief Attempts to establish a WiFi connection with the wireless network,
116+
given _ssid and _pass from the AdafruitIO_Arduino_RenesasUno constructor.
117+
*/
118+
/**************************************************************************/
119+
void _connect() {
120+
if (strlen(_ssid) == 0) {
121+
_status = AIO_SSID_INVALID;
122+
} else {
123+
124+
// check for the WiFi module:
125+
if (WiFi.status() == WL_NO_MODULE) {
126+
Serial.println("Communication with WiFi module failed!");
127+
return;
128+
}
129+
130+
String fv = WiFi.firmwareVersion();
131+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
132+
Serial.print("Firmware version ");
133+
Serial.print(fv);
134+
Serial.print(" is outdated. Latest version is ");
135+
Serial.println(WIFI_FIRMWARE_LATEST_VERSION);
136+
Serial.println("Please upgrade the WiFiS3 firmware!");
137+
return;
138+
}
139+
140+
// disconnect from possible previous connection
141+
_disconnect();
142+
143+
WiFi.begin(_ssid, _pass);
144+
_status = AIO_NET_DISCONNECTED;
145+
}
146+
}
147+
148+
/**************************************************************************/
149+
/*!
150+
@brief Disconnect the wifi network.
151+
*/
152+
/**************************************************************************/
153+
void _disconnect() {
154+
WiFi.disconnect();
155+
delay(AIO_NET_DISCONNECT_WAIT);
156+
}
157+
};
158+
159+
#endif // ADAFRUITIO_RENESAS_UNO_H

0 commit comments

Comments
 (0)