Hi Team! Yesterday I’ve played around Cayenne and my Arduino Mega+LAN shield W5100. Arduino connects to the dashboard fine, but then I am facing lagging of getting the data into the Cayenne dashboard. Data are not continuously displayed, there are still repeated timeouts, if I see the dashboard data are refreshing smoothly just few seconds (10-20) and then there is timeout for another few seconds (10-30, sometime longer). Due to this using for example switch to control a relay is simply impossible ! I’ve tried to run several programs and end up with the only basic program generated by Cayenne, which is showing only the uptime timer, to avoid any code issue and even the timer does not count smoothly due to the timeouts. With the other programs, Arduino works fine, without any issues. Connection from my network to Cayenne works perfect, without any packet loss. What should I check, where should I search for the issue? I would like to use Cayenne for my home automation, but since this mandatory issue It looks useless. Thanks for any help!
this is not an issue. cayenne MQTT library is built in such a way that it sends data every 15 seconds interval to avoid hitting the rate limit and causing device disconnect or block. Have a look at this Sending MQTT messages within rate limits
This explanation makes sense, but anyway, since I also tried to define the CAYENNE_OUT_DEFAULT() parameter using definition 1000 for millis, I faced same issue. It seems that the dashboard simply ignore this settings.
Anyway, In case the dashboard communicate with the arduino board every 15 sec, does it mean, that in case of pressing for example the light switch button connected to binary output for controling the relay, it will wait for the next time period, so it will head to execute the relay statement change in the worst case after 15 seconds? This does not look like very responsive solution for switching the lights in the house …
15 sec is only for sending data from your device to cayenne. For receiving data for example light switch it is instantaneous.
Can you share the code you are using for 1000 miillis.
Aha, I see, thats actually fine, so I will try it again. Unfortunately I am not close to my device now, so I will post the code later on. Thanks for the hint anyway!
Just one question, I am using DHT for temperature and humidity measurement, it works fine, I see the date on the dashboard, but since the issue I mentioned, the counters does not display the figures persistently, so once the dashboard does not receive the data, then the dashboard shows only dashes (like --,-- C and --,-- % humidity) and then after receive the data from arduino again, the figures are displayed and after some time disappears again and this is happens again and again. Is there any function how to display the latest data till the next data connection? It looks like during the refresh interval the data from the sensor are not available at this moment? So some synchronization between the sensor data availability before the dashboard updates?
Are you sure you see — on your dashboard temperature widget. Can you share a screenshot of the same.
Yes, I am definitely sure that I see the data from the sensors and they are relevant. I will post the codes and screens later today.
Here’s the code i use:
//#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>
#include <DHT_U.h>
#define DHTPIN 2
#define DHTPIN2 7
#define DHTTYPE DHT22
DHT_Unified dht(DHTPIN, DHTTYPE);
DHT_Unified dht2(DHTPIN2, DHTTYPE);
#define VIRTUAL_CHANNEL36 V36
#define ACTUATOR_PIN36 36 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL37 V37
#define ACTUATOR_PIN37 37 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL38 V38
#define ACTUATOR_PIN38 38 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define SENSOR_PIN40 40 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL40 40
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxx";
char password[] = "xxx";
char clientID[] = "xxx";
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip(192, 168, 8, 8);
IPAddress dns_ip(192, 168, 8, 1);
IPAddress gateway_ip(192, 168, 8, 1);
IPAddress subnet_mask(255, 255, 255, 0);
void setup() {
Serial.begin(9600);
pinMode(ACTUATOR_PIN36, OUTPUT);
pinMode(ACTUATOR_PIN37, OUTPUT);
pinMode(ACTUATOR_PIN38, OUTPUT);
Cayenne.begin(username, password, clientID, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
dht.begin();
dht2.begin();
sensor_t sensor;
}
void loop()
{
Cayenne.loop();
{
sensors_event_t event;
dht.temperature().getEvent(&event);
Cayenne.celsiusWrite(1, event.temperature);
dht.humidity().getEvent(&event);
Cayenne.virtualWrite(2, event.relative_humidity, "rel_hum", "p");
dht2.temperature().getEvent(&event);
Cayenne.celsiusWrite(3, event.temperature);
dht2.humidity().getEvent(&event);
Cayenne.virtualWrite(4, event.relative_humidity, "rel_hum", "p");
}
}
// 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()
{
Cayenne.virtualWrite(0, millis());
}
// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}
CAYENNE_IN(V36)
{
// 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(ACTUATOR_PIN36, LOW);
}
else {
digitalWrite(ACTUATOR_PIN36, HIGH);
}
}
CAYENNE_IN(V37)
{
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN37, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN37, LOW);
}
}
CAYENNE_IN(V38)
{
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN38, LOW);
}
else {
digitalWrite(ACTUATOR_PIN38, HIGH);
}
}
CAYENNE_OUT(V40)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL40, digitalRead(SENSOR_PIN40));
}
And the screenshots of my dashboard:
As you can see, the values for the temp and humidity sometimes disappears for a while, thats what i mentioned above.
You are continuously sending data in the loop.
Make the following changes:
void loop()
{
Cayenne.loop();
{
sensors_event_t event;
dht.temperature().getEvent(&event);
Cayenne.celsiusWrite(1, event.temperature);
dht.humidity().getEvent(&event);
Cayenne.virtualWrite(2, event.relative_humidity, “rel_hum”, “p”);
```
dht2.temperature().getEvent(&event);
Cayenne.celsiusWrite(3, event.temperature);
dht2.humidity().getEvent(&event);
Cayenne.virtualWrite(4, event.relative_humidity, "rel_hum", "p");
```
}
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite(0, millis());
}
to
void loop()
{
Cayenne.loop();
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite(0, millis());
sensors_event_t event;
dht.temperature().getEvent(&event);
Cayenne.celsiusWrite(1, event.temperature);
dht.humidity().getEvent(&event);
Cayenne.virtualWrite(2, event.relative_humidity, “rel_hum”, “p”);
```
dht2.temperature().getEvent(&event);
Cayenne.celsiusWrite(3, event.temperature);
dht2.humidity().getEvent(&event);
Cayenne.virtualWrite(4, event.relative_humidity, "rel_hum", "p");
```
}