Greetings to the Particle community!
I’m trying to send the readings from my DHT22 sensor to a Particle Console Event. Even though I succesfully compile the firmware, neither temperature nor humidity display in the event’s section of the console. Could someone help me to tell if something is wrong with the syntax within the following code?:
#include <JsonParserGeneratorRK.h>
#include <Adafruit_DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht (DHTPIN, DHTTYPE);
int temp, humidity;
double temp_dbl, humidity_dbl;
const unsigned long UPDATE_INTERVAL = 2000;
unsigned long lastUpdate = 0;
void setup()
{
dht.begin();
Particle.variable("temp", temp_dbl);
Particle.variable("humidity", humidity_dbl);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - lastUpdate >= UPDATE_INTERVAL)
{
lastUpdate = millis();
}
temp = dht.getTempCelcius();
humidity = dht.getHumidity();
temp_dbl = temp;
humidity_dbl = humidity;
Serial.printlnf("Temp: %.f", temp_dbl);
Serial.printlnf("Humid: %.f", humidity_dbl);
}
void createEventPayload(int temp, int humidity)
{
JsonWriterStatic <256> jw;
{
JsonWriterAutoObject obj(&jw);
jw.insertKeyValue("temp",temp);
jw.insertKeyValue("humidity", humidity);
}
Particle.publish("dht-vals", jw.getBuffer(), PRIVATE);
}