Arduino MQTT lots of bugs

yes i’m doing that right know. lets give it a fifth try :stuck_out_tongue:
Thanks for your help, that table for data types was what i needed.

Solved Problem 1 & 3
Screenshot Widget Screen

Something that never worked is the humidity.
It works in a void loop and display in serial but when i execute the code in a CAYENNE_OUT cayenne displays -999. Do you have any knowledge of that?

can you share the entire code you use to get reading from DTH11 sensor.

sure,
The link and my project are using the same library

So i tested the sensor first on this way:
Testing Script

it prints out in serial: 27 degrees and 44% humitidy so it works.

This is how i use it in cayenne:
only the dht11 parts are coppied

#include <dht.h>
dht DHT;
        //Temp DHT11 Channel 0 & Pin 6
        CAYENNE_OUT(0)
        {
          int chk = DHT.read11(6);
          Cayenne.celsiusWrite(0, DHT.temperature);
        }

    //humidity Channel 3 Pin 6
    CAYENNE_OUT(3)
    {
      int chk = DHT.read11(6);
       Cayenne.virtualWrite(3, DHT.humidity, "rel_hum", "p");
    }

Humidity worked when i used a delay of 1000/2000 milliseconds. So i think it doesn’t work because of the cayenne interval time before executing script and sending data

have a look at this code by @adam Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11

It’s because you are not checking the DHT results for errors. Use something like this:

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 Fahrenheit
  t = dht.readTemperature(true);
  //Read humidity (percent)
  h = dht.readHumidity();
  //Read temperature as Fahrenheit
  t = dht.readTemperature(true);
  //Calculate Heat Index as Fahrenheit
  hif = dht.computeHeatIndex(t, h);

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

Code from Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11

1 Like

so as i already thougt. I need to run the code in loop and only sent it in cayenne_out, lets give it a try, thanks

can you also explain why its working much slower after the update?

and no its not my internet :stuck_out_tongue:

Turning om my led strip on relay takes 2 seconds normally instant.

Changing led strip color takes over 8 seconds sometimes!

Is this normal now or is there a fix?

can you post the code.

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include <dht.h>
dht DHT;

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

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID);
  pinMode(24, OUTPUT);
  pinMode(28, OUTPUT);
}

void loop() {
	Cayenne.loop();
}

//Temperatuur DHT11 Channel 0 & Pin 6
CAYENNE_OUT(0)
{
  int chk = DHT.read11(6);
  Cayenne.celsiusWrite(0, DHT.temperature);
}

//Koolstofmonoxide Channel 1 & Pin A0
CAYENNE_OUT(1)
{
  gas_value=analogRead(A0);
  Cayenne.virtualWrite(1, gas_value, "co", "ppm");
}
//Wastafel Lamp Channel 2 Pin 24
CAYENNE_IN(2)
{
  // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
  if (getValue.asInt() == 0) {
    digitalWrite(24, HIGH);
  }
  else {
    digitalWrite(24, LOW);
  }
}

//Vochtigheid Channel 3 Pin 6
CAYENNE_OUT(3)
{
  int chk = DHT.read11(6);
   Cayenne.virtualWrite(3, DHT.humidity, "rel_hum", "p");
}
//Ledstrip Channel 4 Pin 28
CAYENNE_IN(4)
{
  if (getValue.asInt() == 0) {
    digitalWrite(28, HIGH);
  }
  else {
    digitalWrite(28, LOW);
  }
}

//Led Strip Rood
CAYENNE_IN(5)
{
  int currentValue = getValue.asInt(); 
  analogWrite(2, currentValue); 
}

//Led Strip Groen
CAYENNE_IN(6)
{
  int currentValue = getValue.asInt(); 
  analogWrite(3, currentValue); 
}

//Led Strip Blauw
CAYENNE_IN(7)
{
  int currentValue = getValue.asInt(); 
  analogWrite(4, currentValue); 
}

//Lamp Kamer Channel 8 Pin ?
CAYENNE_IN(8)
{
//  if (getValue.asInt() == 0) {
//    digitalWrite(?, HIGH);
//  }
//  else {
//    digitalWrite(?, LOW);
//  }
}

//Rolluik Open Channel 9 Pin ?
CAYENNE_IN(9)
{
//  if (getValue.asInt() == 0) {
//    digitalWrite(?, HIGH);
//  }
//  else {
//    digitalWrite(?, LOW);
//  }
}

//Rolluik Dicht Channel 10 Pin ?
CAYENNE_IN(10)
{
//  if (getValue.asInt() == 0) {
//    digitalWrite(?, HIGH);
//  }
//  else {
//    digitalWrite(?, LOW);
//  }
}

Led strip colors sliders works on pc but takes long. doesn’t work on android at all but thats an common bug

code look fine. what are problem you are facing?

unless the humitidy the only problem is the speed. Before my update to MQTT everything was perfect. When i changed colors of my led strip it changed immediately, now it takes 8 seconds.

And my internet connection is fine

i am not sure why there is a delay. there is a max of 2 sec delay at my end.

i checked it out.
he says DHT sensor library by Adafruit version 1.2.3 is being used but when i use that version or any other version it gives errors about his code.

for example:
DHT dht(DHTPIN, DHTTYPE);

exit status 1
‘DHT’ does not name a type

according to this: Sending MQTT messages within rate limits
Cayenne only uses intervals about 15 seconds.
But that should be with actuators so i don’t think that is it

download and install https://github.com/adafruit/DHT-sensor-library.
next in examples open DHTtester.ino and run.

btw, according to my delay issue. i see here that you fixed it for somebody else :stuck_out_tongue:

did it work for him? i think thats the same issue as me.

that is a different case.

is it? his case is delay on a button>relay. so is mine.

But ok, back to DHT11,

Test works
DHTxx test!
Humidity: 46.00 % Temperature: 27.00 *C 80.60 *F Heat index: 27.18 *C 80.93 *F

i will try to fix it according to this script. i will be back soon.

he wants a return response from the board once the button is pressed.