[SOLVED]Two nodes with relays interfering
-
@MasMat Looks like the gateway's receive function is called even when the gateway is the destination of the message. That results in the gateway updating its relay even though it shouldn't.
I think you could do something like this:
if (message.type==V_STATUS) { if (message.sensor == 0) { // Only switch the relay if the message is for myself Serial.print("Updating relay state"); // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); }@mfalkvidd I've been reviewing this: I have two relays actually attached, so this code will ignore the other completely, right? I think that's why it's not working. Or the numbering for the sensors is different?
Am I wrong or does the "message.sensor" actually refer to child_id rather than node_id? Or am I following this wrong?
-
@mfalkvidd I've been reviewing this: I have two relays actually attached, so this code will ignore the other completely, right? I think that's why it's not working. Or the numbering for the sensors is different?
Am I wrong or does the "message.sensor" actually refer to child_id rather than node_id? Or am I following this wrong?
-
@MasMat I have trouble finding documentation explaining the details, but I think you are right. See if message.destination works better.
@mfalkvidd That fixed it right up and makes complete sense. I couldn't find docs either on message.sensor or message.destination...
The problem now appears more complex...
The GW (node 0) relay STILL follows the other nodes (node 4) commands (completely different circuits, so no electrical connection at all).GW debug (first a on & off test for gw-relay, then clicked the node4-relay, on comes OK (gwrelay follows) but off reboots gw)
0;255;3;0;9;Message arrived on topic: domoticz/out/MyMQTT/0/1/1/0/2 Updating relay stateIncoming change for sensor:1, New status: 1 0;255;3;0;9;Message arrived on topic: domoticz/out/MyMQTT/0/1/1/0/2 Updating relay stateIncoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,4-4-0,s=1,c=1,t=0,pt=7,l=5,sg=0:16.6 0;255;3;0;9;Sending message on topic: domoticz/in/MyMQTT/4/1/1/0/0 0;255;3;0;9;TSF:MSG:READ,4-4-0,s=0,c=1,t=1,pt=7,l=5,sg=0:69.8 0;255;3;0;9;Sending message on topic: domoticz/in/MyMQTT/4/0/1/0/1 0;255;3;0;9;Message arrived on topic: domoticz/out/MyMQTT/4/1/1/1/2 0;255;3;0;9;TSF:MSG:SEND,0-0-4-4,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;TSF:MSG:READ,4-4-0,s=1,c=1,t=2,pt=0,l=1,sg=0:1 0;255;3;0;9;TSF:MSG:ACK 0;255;3;0;9;Sending message on topic: domoticz/in/MyMQTT/4/1/1/1/2 Updating relay stateIncoming change for sensor:1, New status: 1 0;255;3;0;9;Message arrived on topic: domoticz/out/MyMQTT/4/1/1/1/2 0;255;3;0;9;!TSF:MSG:SEND,0-0-4-4,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=NACK:1 0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.1.1 0;255;3;0;9;MCO:BGN:BFR``` -
Nevermind. Whined too soon.
Completely worked over the node4 code, moved "include"s around and eventually changed the relay presentations and receive clauses. Hope this helps someone with their problems later:
Thanks a millions!void before() { // Set relay pin in output mode pinMode(RELAY_1, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(RELAY_1, loadState(CHILD_ID_RELAY)?RELAY_ON:RELAY_OFF); } later this.... present(CHILD_ID_RELAY, S_BINARY); ....and ending with this... void receive(const MyMessage &message) { if (message.type==V_STATUS) { if (message.destination == MY_NODE_ID) { // Only switch the relay if the message is for this node Serial.print("Updating relay state"); // Change relay state digitalWrite(RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID_RELAY, message.getBool()); // Write some debug info } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } -
Nevermind. Whined too soon.
Completely worked over the node4 code, moved "include"s around and eventually changed the relay presentations and receive clauses. Hope this helps someone with their problems later:
Thanks a millions!void before() { // Set relay pin in output mode pinMode(RELAY_1, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(RELAY_1, loadState(CHILD_ID_RELAY)?RELAY_ON:RELAY_OFF); } later this.... present(CHILD_ID_RELAY, S_BINARY); ....and ending with this... void receive(const MyMessage &message) { if (message.type==V_STATUS) { if (message.destination == MY_NODE_ID) { // Only switch the relay if the message is for this node Serial.print("Updating relay state"); // Change relay state digitalWrite(RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID_RELAY, message.getBool()); // Write some debug info } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }@MasMat great work! Maybe change this to make the output more complete?
// Write some debug info Serial.print("Incoming change for sensor:");to
// Write some debug info Serial.print("Incoming change for node: "); Serial.print(message.destination); Serial.print(", sensor:"); -
@MasMat great work! Maybe change this to make the output more complete?
// Write some debug info Serial.print("Incoming change for sensor:");to
// Write some debug info Serial.print("Incoming change for node: "); Serial.print(message.destination); Serial.print(", sensor:");@mfalkvidd That would definitely polish it up! :D
Cheers!!