Hello!
I am currently making a weather station with a DHT, a RTC and a LDR sensor. The code that I made is uploading and the values are showing up on serial but in the dashboard no. Here is the code:
#include <WiFi.h>
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include "DHT.h"
#include "RTClib.h"
#include "thingProperties.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const char ssid[] = "ssid";
const char pass[] = "password";
void setup() {
Serial.begin(9600);
dht.begin();
rtc.begin();
setDebugMessageLevel(4);
// Connect to WiFi
Serial.print("Connecting to WiFi...");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println(" Connected!");
// Initialize Arduino Cloud
initProperties(); // Initialize cloud properties
}
void loop() {
// Read sensor values
float localTemp = dht.readTemperature();
float localHumi = dht.readHumidity();
int localBright = analogRead(A0);
DateTime now = rtc.now();
String localDateTime = String(now.year()) + "-" + String(now.month()) + "-" + String(now.day()) + " "
+ String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second());
// Debug prints
Serial.print("Temperature: "); Serial.println(localTemp);
Serial.print("Humidity: "); Serial.println(localHumi);
Serial.print("Brightness: "); Serial.println(localBright);
Serial.print("DateTime: "); Serial.println(localDateTime);
// Update cloud variables
cloudTemperature = localTemp;
cloudHumidity = localHumi;
cloudBrightness = localBright;
cloudDateTime = localDateTime;
// Update Arduino Cloud
ArduinoCloud.update();
// Delay for a second (adjust as necessary)
delay(1000);
}
And this is the thingProperties.h:
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "device_id";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = SECRET_DEVICE_KEY; // Secret device password
void onCloudBrightnessChange();
void onCloudHumidityChange();
void onCloudTemperatureChange();
float cloudTemperature;
float cloudHumidity;
int cloudBrightness;
String cloudDateTime;
void initProperties() {
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(cloudTemperature, READWRITE, ON_CHANGE, NULL);
ArduinoCloud.addProperty(cloudHumidity, READWRITE, ON_CHANGE, NULL);
ArduinoCloud.addProperty(cloudBrightness, READWRITE, ON_CHANGE, NULL);
ArduinoCloud.addProperty(cloudDateTime, READWRITE, ON_CHANGE, NULL);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
Please help me as soon as possible!