I have a simple IOT sketch that should be reading my DHT22 and returning the temperature but it is not working. I have tried multiple DHTs to no avail. I added a random number and that works. I tested the esp32 and the dht with a library example and things worked.
SKETCH:
/*
Sketch genrated by the Arduino IoT Cloud Thing "Untitled"
https://creeate.arduino.cc/cloud/things/4fc4f4c0-42a3-4668-9f41-322365fea168
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float fhumid;
float ftemp;
int randoNum;
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 <DHT.h>
#include <DHT_U.h>
#define DHTPIN 4
#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();
// 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(5000);
randoNum = random(1000);
ftemp = (dht.readTemperature() * 1.8) + 32;
fhumid = dht.readHumidity();
Serial.print("temperature is ");
Serial.println(ftemp);
Serial.println("this is a test");
Serial.println(randoNum);
Serial.print("humidity is ");
Serial.println(fhumid);
}
MONITOR DUMP:
L�$
�¡aI��***** Arduino IoT Cloud - configuration info *****
Device ID: 1944616a-357c-491a-aaf9-a25ce58b80f9
MQTT Broker: mqtts-up.iot.arduino.cc:8884
WiFi.status(): 255
temperature is nan
this is a test
189
humidity is nan
Connection to "SouthKlein" failed
Retrying in "4000" milliseconds
temperature is nan
this is a test
184
humidity is nan
Connected to "SouthKlein"
temperature is nan
this is a test
846
humidity is nan
temperature is nan
this is a test
121
humidity is nan
temperature is nan
this is a test
174
humidity is nan
temperature is nan
this is a test
249
humidity is nan
temperature is nan
this is a test
656
humidity is nan
ArduinoIoTCloudTCP::handle_WaitDeviceConfig device waiting for valid thing_id
temperature is nan
this is a test
221
humidity is nan
temperature is nan
this is a test
313
humidity is nan
temperature is nan
this is a test
686
humidity is nan
temperature is nan
this is a test
280
humidity is nan
Connected to Arduino IoT Cloud
Thing ID: 4fc4f4c0-42a3-4668-9f41-322365fea168
--
Steve Klein
1stQuartile@gmail.com