Dht22 / cayenne


#41

I’m not sure what to say. I’m using the same code with a NodeMCU and it works. According to your output yours does too. Have you looked at the graph view for the widgets? Here is a screen shot of mine (the straight line is when my battery died and forgot to replace it)


#42

I just changed the setting to sleep at one minute but in the console is still the same information to know the anomaly of the last line

console


#43

do what @adam suggested. have a look at the Graph view.


#44

Implementation of the code (adam) at 1h15 since no new value and the anomaly at the bottom of the console serie.


#45

No new values? The graph is changing, what are you expecting to see?


#46

ERROR into the serial console

console


#47

The graph changes until 1:15 because I did not put in the code the sleep function


#48

CODE SLEEPING FUNCTION after 1h15

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define DHTTYPE DHT22
#define DHTPIN  4

#include <CayenneMQTTESP8266.h>
#include <DHT.h>

// WiFi network info.
char ssid[] = "XXX";
char wifiPassword[] = "XXX";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "XXX";
char password[] = "XXX";
char clientID[] = "XXX";

//Variables for DHT11 values
float h, t, hif;
//Time to sleep - 10 minutes - delete a zero to set to 1 minute
int SleepTime = 60000000;
//Values sent/error booleans
bool CayenneSent = false;
bool ReadError = false;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("Setup");
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);

  CayenneSent = false;
  ReadError = true;
}

void loop() {
  //Run Cayenne Functions
  Cayenne.loop();

  //Only check values if there is a ReadError 
  if (ReadError){
    ReadError = false;
    //Check if read failed and try until success
    int WhileLoops = 0;
    do {
      WhileLoops++;
      //We can't go too long without calling Cayenne.loop() so exit this loop after 2 seconds and set an error flag
      if (WhileLoops >= 4){
        Serial.println("Sensor Read Error");
        ReadError = true;
        break;
      }
      //Read temperature as Celsius
      t = dht.readTemperature();
      //Read humidity (percent)
      h = dht.readHumidity();
      //Read temperature as Celsius
      t = dht.readTemperature();
      //Calculate Heat Index as Celsius
      hif = dht.computeHeatIndex(t, h);
  
      delay(500);
    } while  (isnan(t) || isnan(h));

    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temperature (c): ");
    Serial.println(t);
    Serial.print("Heat Index (c): ");
    Serial.println(hif);
  }
  else {
    //Check if we sent all values and sleep for 10 minutes if we did
    if (CayenneSent){
      Serial.println("Sent all values - sleeping");
      delay(100);
      ESP.deepSleep(SleepTime, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
}
    
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  //Check if there was a read error and skip sending values if there is
  if (!ReadError){
    //Send Values
    Cayenne.virtualWrite(0, h, "rel_hum", "p");
    Cayenne.virtualWrite(1, t, "temp", "c");
    Cayenne.virtualWrite(2, hif, "temp", "c");

    //Set CayenneSent to true so we know when to sleep
    CayenneSent = true;
  }
}

#49

CODE BEFORE 1H15 without sleeping function

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define DHTTYPE DHT22
#define DHTPIN  4

#include <CayenneMQTTESP8266.h>
#include <DHT.h>

// WiFi network info.
char ssid[] = "XXX";
char wifiPassword[] = "XXX";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "XXX";
char password[] = "XXX";
char clientID[] = "XXX";

//Variables for DHT22 values
float h, t, hif;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("Setup");
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);

}

void loop() {
  //Run Cayenne Functions
  Cayenne.loop();

  
      //Read temperature as Celsius
      t = dht.readTemperature();
      //Read humidity (percent)
      h = dht.readHumidity();
      //Read temperature as Celsius
      t = dht.readTemperature();
      //Calculate Heat Index as Celsius
      hif = dht.computeHeatIndex(t, h);
  
      delay(500);
 

    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temperature (c): ");
    Serial.println(t);
    Serial.print("Heat Index (c): ");
    Serial.println(hif);

      
      
    Cayenne.virtualWrite(0, h, "rel_hum", "p");
    Cayenne.virtualWrite(1, t, "temp", "c");
    Cayenne.virtualWrite(2, hif, "temp", "c");

   delay(5000);
  }

#50

Use my original code and modify this line:

int SleepTime = 60000000;

This will sleep for 1 minute and will be easier for you to see the values on the dashboard. After you upload the new code to the device watch your dashboard. If you haven’t already, make the widgets permanent with the green +. Let it run for a minimum of 15 minutes then come back and check your graph again and post a screen shot of it.


#51

As requested I changed the code hereof below the detail.

I will wait 15 to 20 minutes and make the screenshot

//Variables for DHT11 values
float h, t, hif;
//Time to sleep - 10 minutes - delete a zero to set to 1 minute
int SleepTime = 60000000;
//Values sent/error booleans
bool CayenneSent = false;
bool ReadError = false;


#52

I start my device at 14h46mn20s

With this code

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define DHTTYPE DHT22
#define DHTPIN 4

#include <CayenneMQTTESP8266.h>
#include <DHT.h>

// WiFi network info.
char ssid[] = “XXX”;
char wifiPassword[] = “XXX”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “XXX”;
char password[] = “XXX”;
char clientID[] = “XXX”;

//Variables for DHT11 values
float h, t, hif;
//Time to sleep - 10 minutes - delete a zero to set to 1 minute
int SleepTime = 600000000;
//Values sent/error booleans
bool CayenneSent = false;
bool ReadError = false;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println(“Setup”);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

CayenneSent = false;
ReadError = true;
}

void loop() {
//Run Cayenne Functions
Cayenne.loop();

//Only check values if there is a ReadError
if (ReadError){
ReadError = false;
//Check if read failed and try until success
int WhileLoops = 0;
do {
WhileLoops++;
//We can’t go too long without calling Cayenne.loop() so exit this loop after 2 seconds and set an error flag
if (WhileLoops >= 4){
Serial.println(“Sensor Read Error”);
ReadError = true;
break;
}
//Read temperature as Celsius
t = dht.readTemperature();
//Read humidity (percent)
h = dht.readHumidity();
//Read temperature as Celsius
t = dht.readTemperature();
//Calculate Heat Index as Celsius
hif = dht.computeHeatIndex(t, h);

  delay(500);
} while  (isnan(t) || isnan(h));

Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature (c): ");
Serial.println(t);
Serial.print("Heat Index (c): ");
Serial.println(hif);

}
else {
//Check if we sent all values and sleep for 10 minutes if we did
if (CayenneSent){
Serial.println(“Sent all values - sleeping”);
delay(100);
ESP.deepSleep(SleepTime, WAKE_RF_DEFAULT);
delay(100);
}
}
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
//Check if there was a read error and skip sending values if there is
if (!ReadError){
//Send Values
Cayenne.virtualWrite(0, h, “rel_hum”, “p”);
Cayenne.virtualWrite(1, t, “temp”, “c”);
Cayenne.virtualWrite(2, hif, “temp”, “c”);

//Set CayenneSent to true so we know when to sleep
CayenneSent = true;

}
}

In my serial console

console

in my cayenne interface

im wait 15 mn and im post the message


#53

What about the graph?


#54

At 14h56mn20s i have

in my console

console

In my cayenne interface

In my graph


#55

can you set the graph to minutes.


#56


#57

Looks like graphs were having issues, I checked mine at the same time and also had no data. Should work now (does for me anyway). Also, did you leave the device on? if it’s not sending data of course there will not be anything to show for the last hour.


#58

I have not cut anything since 14h46


#59

So what does your hour/minute graph show now?


#60

It looks like there are some issues right now. Sorry for going back and forth on this, but I would suggest waiting until everything is back up and running correctly again before trying anything else.