Relays Synchronisation

Hello, I hace noticed now with the MQTT transition that actuators do not behave as before. For example when i press a button widget to activate a motor or a lamp, the change in the button state do not appear in all devices i.e phone, tablet, dashboard. Also sometimes i have enable/disable the button twice in order to activate the relay. I dont know if this problem has any relation with the connection rate limit, messages and millis function.

Regards

i am not sure why phone and dashboard are not same, maybe @jcruz can help out this. one workaround can be use Cayenne.virtualWrite(0, x); where x stores the value of channel 0 (actuator).

Hi @ufrtgr,

Can you post the code you’re using?
Maybe some screenshots of a side by side of Web vs App (Android or iOS?)

Thanks.

hi, some screenshots below. Board is Arduino Ethernet. I am showing a case with relays.

First Case: I open the dash and for some reason the motor relay is enabled only in dashboard, but not in mobile.

Second Case: Afterwards i press the light relay from the mobile and in dashboard nothing updates.

Also i want to mention that most of the times when i press a relay to activate from dash it crashes, see picture attached below.

Code is coming.

try this.

@ufrtgr I have same issue, tryed all code combinations but non of them works on both platforms, and relay dont even activate when using android application. As i mentioned here http://community.mydevices.com/t/release-notes-march-21-2018-4-new-widgets-and-bug-fixes/8815/4?u=agroelektronik Cayenne has synchronization issues and inconsistency between phone application and web/desktop, but no fix even 3 months after mqtt changes started.

Code is below.

include <CayenneMQTTEthernet.h>

#define VIRTUAL_CHANNEL_1 3
#define VIRTUAL_CHANNEL_2 4

#define ACTUATOR_PIN_5 5
#define ACTUATOR_PIN_6 6

const int AnalogPin = 1;

float Waterlevel, WaterDistance, distance, level;
long AnalogVolt;
float Waterfull = 30;
float Waterempty = 140;
unsigned int lastMillis;
boolean currentValue, getValue;

char username = “”;
char password = “”;
char clientID = “”;

byte mac = { 0x90, 0xA2, 0xDA, 0x0D, 0x68, 0x9E };
IPAddress ip(192, 168, 1, 175);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetClient client;

void setup()
{
//Serial.begin(9600);
delay(10);
digitalWrite(ACTUATOR_PIN_5, HIGH);
digitalWrite(ACTUATOR_PIN_6, HIGH);
pinMode(ACTUATOR_PIN_5, OUTPUT);
pinMode(ACTUATOR_PIN_6, OUTPUT);
Cayenne.begin(username, password, clientID);
Ethernet.begin(mac, ip);
}

void loop()
{
Cayenne.loop();
if (millis() - lastMillis > 5000) {
lastMillis = millis();
readMaxbotix();
Waterlevel = map(WaterDistance, Waterfull, Waterempty, 100, 0);
Cayenne.virtualWrite(0, millis());
Cayenne.virtualWrite(1, Waterlevel, “tl”, “null”);
Cayenne.virtualWrite(2, WaterDistance, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
}

void readMaxbotix(){
AnalogVolt = analogRead(AnalogPin);
distance = AnalogVolt * 5;
WaterDistance = distance/10;
}

CAYENNE_IN(VIRTUAL_CHANNEL_1)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1
// assuming you wire your relay as normally open
if (currentValue == 0) {
digitalWrite(ACTUATOR_PIN_5, HIGH);
} else {
digitalWrite(ACTUATOR_PIN_5, LOW);
}
}

CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1
// assuming you wire your relay as normally open
if (currentValue == 0) {
digitalWrite(ACTUATOR_PIN_6, HIGH);
} else {
digitalWrite(ACTUATOR_PIN_6, LOW);
}
}

add and make the following changes and give it a try

 unsigned long lastMillis1 = 0;

 if (millis() - lastMillis1 > 10000) {
lastMillis1 = millis()
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, x);
}   

CAYENNE_IN(VIRTUAL_CHANNEL_1)
    {
    int x= getValue.asInt(); 
    digitalWrite(ACTUATOR_PIN_5, x);
    }

I have tried the 10 second interval, no change. Rest i will try.

it is not about 10 sec timer, both the code work together. the value of x is used to turn on the actuator and also keep the widget status on dashboard same as the the actuator.

I am afraid not much difference. I have noticed that only boards like nodeMCU, Arduino Yun, WemosD1 runs smoothly with new MQTT library. Arduino Uno, Arduino Ethernet have problems.

Do you have another ethernet shield you can try? There have been a few people so far having similar issues in the past that had a bad shield. The knockoffs are cheap but you get what you pay for.

Yes i have also other boards and they are official. The same problem in these too.

Before the transition to the MQTT protocol, especially the relays where working perfect, very accurate and fast response, with the same boards, cheap or not. Does the MQTT protocol identifies whether a board is original or not?

No, it does not care what the hardware is. There were recently some MQTT server issues but it seems to be mostly cleared up. I just checked a few minutes ago.

Guys, I see some problem like this for actuators. Does it still happening?

this issue has been solved. are you referring to something similar?

Hello there, after some time, still the synchronisation/update between web dashboard and app is not working regarding relays/actuators. Any suggestions?

Regards,

it works fine on my end. can you refresh the app when the issue occurs to see the changes made on the relays/actuators.