Hi. I have recently been working with the IoT LED cloud sketch (turning a red LED on and off) which is working well until the Arduino R4 board keeps disconnecting from the network. It is really frustrating since it works form the dashboard in the browser and on the mobile app. But then the Device in the devices tab keeps stating OFFLINE and the board stops responding. Please can someone help me to resolve this issue - is it something to do with the WiFI network credentials. Thanks, Matt
(PS not connected the DHT22 yet until I can resolve this ongoing issue)
this is the code that i am using:
/*
Sketch generated by the Arduino IoT Cloud Thing "Office LED and Temp_Humid sensor"
https://create.arduino.cc/cloud/things/d82d9300-8faa-437d-8293-5ed16b16eb80
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float boardHUMID;
float boardTEMP;
bool redLED;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
int myLED = 8;
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
pinMode(myLED,OUTPUT);
dht.begin();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
delay(2000);
boardTEMP = dht.readTemperature();
boardHUMID = dht.readHumidity();
}
/*
Since RedLED is READ_WRITE variable, onRedLEDChange() is
executed every time a new value is received from IoT Cloud.
*/
void onRedLEDChange() {
// Add your code here to act upon RedLED change
Serial.println(redLED);
if(redLED){
digitalWrite(myLED,HIGH);
} else{
digitalWrite(myLED,LOW);
}
}
It looks life the ARduino UNO R4's Wifi disconnection problem is not uncommon.
You may find some clues from the following discussions.
@aliarifat many thanks for this. I will try this out and see how it goes.