Hi,,
after fifteen months spent trying to learn how to use Arduino and ESp32 ( I'm an old newbie, 73 y old) I just subscribed a plan on Arduino IOT Cloud.
I started with some very basic code just trying to collect data from a BME280 sensor and time from a RTC DS3231 ( since I was able with this mCU and sensor to build a datalogger with deepsleep)
Here is the code
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/574c711a-04be-4b20-8972-1e34d8a4cc3b
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float hum;
float temp;
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"
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
#include <RTClib.h>
RTC_DS3231 rtc;
void gettimeStamp() {
DateTime now = rtc.now();
char timeStamp[9];
sprintf(timeStamp, "%02i:%02i:%02i", now.hour(), now.minute(), now.second());
Serial.println(timeStamp);
}
void setup() {
// Initialize serial and wait for port to open:
//initializing Serial monitor
Serial.begin(115200);
while(!Serial);
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
delay(4000);
/*
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();
Serial.println("Initialize DS3231");
// setup for the RTC
while(!Serial);
delay(1000);
if(! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
else {
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
bme.begin(0x76);
temp = bme.readTemperature();
hum= bme.readHumidity();
}
void loop() {
ArduinoCloud.update();
// Your code here
temp = bme.readTemperature();
hum= bme.readHumidity();
gettimeStamp();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println( "°C");
Serial.print("Humidity: ");
Serial.print(hum);
Serial.println("%");
DateTime now = rtc.now();
char timeStamp[9];
sprintf(timeStamp, "%02i:%02i:%02i", now.hour(), now.minute(), now.second());
Serial.println(timeStamp);
delay(180000);
}
However, even if in the dashboard I linked the variable time to timeStamp I still get the UTC time and not the time from RTC ( which is just one hour late in my timezone) both in the serial monitor and in the dashboard.
Furthermore I don't understand how the dashboard data from sensor are updated because it seems that only time ( even if with one hour difference is updated) while the temp and hum values show a great lag and even refreshing the dashboard shows no effect on data.
I googled in search of solutions but I was not able to find one.
I'm really very grateful if you could help me.
Thx in advance for your help.