Hi, I am using arduino IOT cloud for my project. I am currently using 2 arduino mkr 1010 devices and have defined a project for each one.
The idea is to use the 2nd one as a slave, having connected an env shield which measures variables such as temperature, humidity, etc. My 1st device is used as a master which displays these variables in an lcd display screen. The variables defined in the 1st project are linked with the ones in the 2nd one via iot cloud.
Once I run the project it works propperly for the first 5 seconds but after that an error is shown in my 2nd project serial port "ArduinoIoTCloudTCP::handle_Disconnect MQTT client connection lost" and the sensor values no longer upload to the 2nd project.
I have an idea of what might be causing the problem, arduino iot cloud refresh time might be too frequent, I tried to change the refreshing time of the values but this doens't solve the error. Does anyone have experience working with arduino iot cloud ?
1st project code:
#include <Arduino_MKRENV.h>
#include "thingProperties.h"
int muestras;
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();
// 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();
if (!ENV.begin()) {
Serial.println("Failed to initialize MKR ENV shield!");
while (1);
}
}
void loop() {
ArduinoCloud.update();
// Your code here
muestras = analogRead(A2);
mV = map(muestras, 0, 1024, 0, 5000);
co2 = map(mV, 0, 5000, 0, 10000);
temperature = ENV.readTemperature();
humidity = ENV.readHumidity();
}
/*
Since BoolSync is READ_WRITE variable, onBoolSyncChange() is
executed every time a new value is received from IoT Cloud.
*/
void onBoolSyncChange() {
// Add your code here to act upon BoolSync change
Serial.print(mV);
Serial.println(" mV");
Serial.print(co2);
Serial.println(" ppm");
temperature = ENV.readTemperature();
humidity = ENV.readHumidity();
Serial.print(temperature);
Serial.println(" ºC");
Serial.print(humidity);
Serial.println(" %");
}
/*
Since MV is READ_WRITE variable, onMVChange() is
executed every time a new value is received from IoT Cloud.
*/
void onMVChange() {
// Add your code here to act upon MV change
}
/*
Since Co2 is READ_WRITE variable, onCo2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onCo2Change() {
// Add your code here to act upon Co2 change
}
/*
Since Temperature is READ_WRITE variable, onTemperatureChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange() {
// Add your code here to act upon Temperature change
}
/*
Since Humidity is READ_WRITE variable, onHumidityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHumidityChange() {
// Add your code here to act upon Humidity change
`
2nd project code:
#include "thingProperties.h"
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
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();
// 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
}
/*
Since BoolSync2 is READ_WRITE variable, onBoolSync2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onBoolSync2Change() {
// Add your code here to act upon BoolSync2 change
/*
if(bool_sync_2 = true)
{
lcd.begin(16, 2);
lcd.print("Pulsa boton para");
lcd.setCursor(0,1);
lcd.print("mostrar parametros AQI");
}
else
{
lcd.begin(16, 2);
lcd.print("CO2: ");
lcd.print(co2_2);
lcd.print("Temperatura: ");
lcd.print(temperature_2);
lcd.print(" ºC");
lcd.setCursor(0,1);
lcd.print("Humedad: ");
lcd.print(humidity_2);
lcd.print(" %");
}
*/
}
/*
Since Co22 is READ_WRITE variable, onCo22Change() is
executed every time a new value is received from IoT Cloud.
*/
void onCo22Change() {
// Add your code here to act upon Co22 change
lcd.begin(16, 2);
lcd.print("Parametros AQI: ");
lcd.setCursor(0,1);
lcd.print("CO2: ");
lcd.print(co2_2);
lcd.print(" ppm");
}
/*
Since Temperature2 is READ_WRITE variable, onTemperature2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperature2Change() {
// Add your code here to act upon Temperature2 change
}
/*
Since Humidity is READ_WRITE variable, onHumidityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHumidityChange() {
// Add your code here to act upon Humidity change
}
/*
Since Humidity2 is READ_WRITE variable, onHumidity2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onHumidity2Change() {
// Add your code here to act upon Humidity2 change
}




