Arduino MQTT lots of bugs

After the update to MQTT on my arduino Mega with Ethernet shield w5100 i am only getting problems.
Buttons aren´t working, sliders don´t slide data is being processed wrong etc.

This is my 4th clean install in 2 days because nothing works anymore.

Problem 1, Widget doesn’t displays value although it is beeing received

For example my CO sensor:
//CO Channel 1 & Pin A0
CAYENNE_OUT(1)
{
gas_value=analogRead(A0);
Cayenne.virtualWrite(1, gas_value);
}

Works great, this is what cayenne receives:
Screenshot Data

What it displays:
Screenshot Widget Overview

Widget Settings:
Screenshot Widget Settings

How can it be so hard to display a number?

Problem 2, DHT11 Humidity:
when i use my dht11 script outside the cayenne_out function it works (when i apply a delay of 1sec because this old sensor only sends good data when using a delay). it gives me a INT of 44. but when i use it in CAYENNE_OUT (with or without delay) It displays -999.00 all the time. I think because of the interval time cayenne uses but i can’t change that.

Is there somebody who also uses DHT11 on cayenne who can explain me how to fix this?

//Humidity DHT11 Channel 1 & Pin 6
CAYENNE_OUT(1)
{
int chk = DHT.read11(6);
Cayenne.virtualWrite(1, DHT.humidity); <— This works in a void loop but not here!
}

Problem 3, can’t click button on mobile/android:
Now that i am using MQTT i rebuilded my widgets but on pc i can click them and they stay clicked but on my phone they don’t lock they just go on and off.

I fixed this earlier by using “Bring Your Own Thing” but i want to use Arduino instead od the API. so that isn’t a option for me.

Problem 4, slider that can’t slide:
Using a light slider on pc: Can’t slide at all.
Using slider on phone. Can slide but only between 0 and 1 while i set range of 0-255.
When i try to slide i get this error: “cannot remote to remote device” but sensor data is updating well.

So the only thing that works after MQTT is temperature… Great update i would say…hope to hear from somebody soon.

seems like there are plenty of error with your coding.

change this:

to
Cayenne.virtualWrite(1, gas_value, "co2", "ppm");

change this:

to
Cayenne.virtualWrite(1, chk, "rel_hum", "p");

this is the solution but it is same as Arduino and not API. you will get the MQTT credential and add them in your previous code and follow the same procedure.

already using MQTT credentials.

about those coding errors:
After reading documentaion the only thing i could find was Cayenne.virtualWrite.
Where did you find those other options?

get this from BYOT and add the device.

I made a light switch widget (relay).
It works on PC know but not on my android device. (Clicking but goes on and off).

I am using Arduino instead of BYOT.

try to add a new device using BYOT and then a custom button widget to turn on/off relay. this will work.

i know i tried that already but i don´t understand why cayene made A Arduino option if this options doesn´t even work and every arduino user should use BYOT.

And with BYOT i can only use custom widgets and that takes more time.

team is working on fixing all the bugs and require some time.

with BYOT device you can do all the things that the Arduino device can do. what problem are you facing using a BYOT device?

lets start at the beginning. When selecting arduino device i am getting a example code wich works good.

i always have been using that type of code but when i use BYOT device i get a code that doesn´t work on my Arduino Mega.

So should i use the same code on BYOT as i am using now on arduino device?

in your arduino ide examples you will find all the code for different device connection.

open the code you want. example for you it will Ethernet shield 5100 (my guess) and arduino mega.

in the code:

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

this MQTT credential you will get from BYOT.

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.