Relays Synchronisation


#1

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


#2

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).


#3

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.


#4

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.


#5

try this.


#6

@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.


#7

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);
}
}


#8

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);
    }

#9

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


#10

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.


#11

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.


#12

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.


#13

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


#14

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?


#15

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.