I have been using an Arduino Ethernet Shield 5100 and 5500 on both a Uno and Mega successfully on Cayenne.
However, I have moved to a new room in the house that is a long way from my router, so I have invested in some new Arduino Uno Wifi Rev 2, assuming I could connect them to Cayenne.
However, it seems that they are not compatible and there isnt any libraries for them.
Am I missing something?
I should have said, that I have tried all of the options, such as the MKR etc, but they do not work.
The code for my mini project (while I am learning Arduino) was as follows:
/* Program to read data frm a DHT11 sensor and connect to the
* Cayenne IoT servers via the Uno WiFi Rev 2*/
// DHT 11 sensor libraries and configuration.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
// Include WiFiNINA libraries.
#include <SPI.h>
#include <WiFiNINA.h>
// WiFi network info.
#include "arduino_secrets.h" // SSID and password file
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the Wifi radio's status
// Digital pin connected to the DHT sensor.
#define DHTPIN 8
// Define sensor type.
#define DHTTYPE DHT11
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
// Cayenne libraries.
#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTWiFi.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "HIDDEN";
char password[] = "HIDDEN";
char clientID[] = "HIDDEN";
// Cayenne virtual channel 1 (relay).
#define VIRTUAL_CHANNEL 2 // DHT11 sensor
#define ACTUATOR_PIN 2 // Relay
/*-----------------------------------------------------------------*/
void setup( )
{
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
} // Close while.
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
} // Close if.
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
} // Close if.
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
} // Close while.
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
// Begin serial interface.
Serial.begin( 9600);
// Begin DHT 11 sensor.
dht.begin();
dht11SensorInfo ();
// Begin Cayenne interface.
Cayenne.begin(username, password, clientID);
} // Close setup.
/*-----------------------------------------------------------------*/
void loop( )
{
// Begin Cayenne loop.
Cayenne.loop();
pinMode (ACTUATOR_PIN, OUTPUT);
} // Close loop.
/*-----------------------------------------------------------------*/
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
//Cayenne.virtualWrite(0, millis());
sensors_event_t event;
dht.temperature().getEvent(&event);
Cayenne.celsiusWrite(1, event.temperature);
dht.humidity().getEvent(&event);
Cayenne.virtualWrite(3, event.relative_humidity, "rel_hum", "p");
} // Close function.
/*-----------------------------------------------------------------*/
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN, HIGH);
} // Close if.
else {
digitalWrite(ACTUATOR_PIN, LOW);
} // Close else.
} // Close function.
/*-----------------------------------------------------------------*/
/*****
* Function definition: dht11SensorInfo
*
* Purpose: Print sensor information on start up
*
* Parameters:
*
* void
*
* Return value:
*
* void
*
*****/
// Print sensor data.
void dht11SensorInfo (void) {
Serial.println(" ");
Serial.println(F("DHTxx Unified Sensor Example"));
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.println(F("Temperature Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
Serial.println(F("------------------------------------"));
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println(F("Humidity Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
Serial.println(F("------------------------------------"));
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
} // Close function.
/*-----------------------------------------------------------------*/
/*****
* Function definition: connectWiFiNetwork
*
* Purpose: Connect to WiFi network
*
* Parameters:
*
* void
*
* Return value:
*
* void
*
*****/
void connectWiFiNetwork (void) {
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
} // Close function.
/*-----------------------------------------------------------------*/
/*****
* Function definition: printCurrentNet
*
* Purpose: Prints current network information
*
* Parameters:
*
* void
*
* Return value:
*
* void
*
*****/
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
Serial.println();
} // Close function.
/*-----------------------------------------------------------------*/
/*****
* Function definition: printWifiData
*
* Purpose: Prints WiFi network data.
*
* Parameters:
*
* void
*
* Return value:
*
* void
*
*****/
void printWifiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
} // Close function.
/*-----------------------------------------------------------------*/
/*****
* Function definition: printMacAddress
*
* Purpose: Prints network device MAC address.
*
* Parameters:
*
* void
*
* Return value:
*
* byte mac address
*
*****/
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
} // Close if.
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
} // Close if.
} // Close for.
Serial.println();
} // Close function.
/*-----------------------------------------------------------------*/