Tried that. No change.
Brian Morris
@Brian Morris
Best posts made by Brian Morris
Latest posts made by Brian Morris
-
Switching gateway issues
Howdy all,
I currently have a ESP8266 Wemos based gateway that I have been using for years. I am flipping over to using a Orange Pi Zero based gateway and everything is working with the MQTT part, it connects to the MQTT gateway on my Home Assistant instance, but I only see the "/mysgw1-in/0/255/0/0/18 2.3.1" message. I see its doing things like:
Dec 02 14:35:45 INFO Starting gateway... Dec 02 14:35:45 INFO Protocol version - 2.3.1 Dec 02 14:35:45 DEBUG MCO:BGN:INIT GW,CP=RNNGL-Q-,REL=255,VER=2.3.1 Dec 02 14:35:45 DEBUG TSF:LRT:OK Dec 02 14:35:45 DEBUG TSM:INIT Dec 02 14:35:45 DEBUG TSF:WUR:MS=0 Dec 02 14:35:45 DEBUG TSM:INIT:TSP OK Dec 02 14:35:45 DEBUG TSM:INIT:GW MODE Dec 02 14:35:45 DEBUG TSM:READY:ID=0,PAR=0,DIS=0 Dec 02 14:35:45 DEBUG MCO:REG:NOT NEEDED Dec 02 14:35:45 DEBUG MCO:BGN:STP Dec 02 14:35:45 DEBUG MCO:BGN:INIT OK,TSP=1 Dec 02 14:35:45 DEBUG GWT:RMQ:MQTT RECONNECT Dec 02 14:36:00 DEBUG connected to 10.200.62.50 Dec 02 14:36:00 DEBUG GWT:RMQ:MQTT CONNECTED Dec 02 14:36:00 DEBUG GWT:TPS:TOPIC=/mysgw1-in/0/255/0/0/18,MSG SENT Dec 02 14:36:00 DEBUG TSM:READY:NWD REQ Dec 02 14:36:13 DEBUG TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK: Dec 02 14:50:45 DEBUG TSF:SAN:OK
But the nodes I have deployed dont want to talk to this new gateway. Even though its the same gateway ID and such. Here is a debug from one of my sensors. Any ideas?
__ __ ____ | \/ |_ _/ ___| ___ _ __ ___ ___ _ __ ___ | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __| | | | | |_| |___| | __/ | | \__ \ _ | | \__ \ |_| |_|\__, |____/ \___|_| |_|___/\___/|_| |___/ |___/ 2.3.1 208 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1 331 TSM:INIT 344 TSF:WUR:MS=0 368 TSM:INIT:TSP OK 389 TSM:INIT:STATID=14 413 TSF:SID:OK,ID=14 436 TSM:FPAR 483 TSF:MSG:SEND,14-14-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2560 !TSM:FPAR:NO REPLY 2584 TSM:FPAR 2633 TSF:MSG:SEND,14-14-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 4710 !TSM:FPAR:NO REPLY 4734 TSM:FPAR 4784 TSF:MSG:SEND,14-14-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 6860 !TSM:FPAR:NO REPLY 6885 TSM:FPAR 6934 TSF:MSG:SEND,14-14-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 9011 !TSM:FPAR:FAIL 9031 TSM:FAIL:CNT=1 9052 TSM:FAIL:DIS 9070 TSF:TDI:TSL
-
RE: MQTT Gateway: Add a confirmation/acknowledgement to the publish topic upon setting via subscribe topic.
with it here, I attempt to turn on the switch by sending a payload of "1" to turn on the switch via MQTT. The gateway receives it, sends it to the node, where the node reverses it, sends it back 0. I can press the button many times over, stays 0/off.
void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } else if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID, state); send(msg.set(state?false:true)); if (state == true){ colorSet(strip.Color(0, 255, 0)); // Green } else { colorSet(strip.Color(255, 255, 255)); // White }
Node DEBUG
0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1 4 TSM:INIT 4 TSF:WUR:MS=0 12 TSM:INIT:TSP OK 14 TSM:INIT:STATID=80 16 TSF:SID:OK,ID=80 18 TSM:FPAR 55 TSF:MSG:SEND,80-80-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 557 TSF:MSG:READ,0-0-80,s=255,c=3,t=8,pt=1,l=1,sg=0:0 563 TSF:MSG:FPAR OK,ID=0,D=1 2062 TSM:FPAR:OK 2062 TSM:ID 2064 TSM:ID:OK 2066 TSM:UPL 2070 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2076 TSF:MSG:READ,0-0-80,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2082 TSF:MSG:PONG RECV,HP=1 2086 TSM:UPL:OK 2088 TSM:READY:ID=80,PAR=0,DIS=1 2127 !TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=NACK:0100 4136 TSF:MSG:SEND,80-80-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=1,st=OK:2.1.1 4147 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 6158 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:Living Room Fan Switch 6170 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.5 6178 TSF:MSG:SEND,80-80-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 6187 MCO:REG:REQ 6191 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 6197 TSF:MSG:READ,0-0-80,s=255,c=3,t=27,pt=1,l=1,sg=0:1 6203 MCO:PIM:NODE REG=1 6207 MCO:BGN:STP 8660 MCO:BGN:INIT OK,TSP=1 170743 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1 170752 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 Incoming change for sensor:1, New status: 1 173297 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1 173305 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 Incoming change for sensor:1, New status: 1 294385 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:0 294391 TSF:MSG:ACK This is an ack from gateway
GW
0;255;3;0;9;MCO:BGN:STP 0;255;3;0;9;MCO:BGN:INIT OK,TSP=1 IP: 10.200.62.10 0;255;3;0;9;Attempting MQTT connection... 0;255;3;0;9;MQTT connected 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/0/0/18 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/11 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/12 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/10/0/0/3 pm open,type:2 0 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,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,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,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,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0
moving it to here, the physical switch stays at 1 no matter how many times you click. Controller to MQTT works and the switch works, but still no response back to the controller.
void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); send(msg.set(state?false:true)); } else if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID, state); if (state == true){ colorSet(strip.Color(0, 255, 0)); // Green } else { colorSet(strip.Color(255, 255, 255)); // White }
Node
0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1 4 TSM:INIT 4 TSF:WUR:MS=0 12 TSM:INIT:TSP OK 14 TSM:INIT:STATID=80 16 TSF:SID:OK,ID=80 18 TSM:FPAR 55 TSF:MSG:SEND,80-80-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 704 TSF:MSG:READ,0-0-80,s=255,c=3,t=8,pt=1,l=1,sg=0:0 708 TSF:MSG:FPAR OK,ID=0,D=1 2062 TSM:FPAR:OK 2062 TSM:ID 2064 TSM:ID:OK 2066 TSM:UPL 2070 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2084 TSF:MSG:READ,0-0-80,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2091 TSF:MSG:PONG RECV,HP=1 2093 TSM:UPL:OK 2095 TSM:READY:ID=80,PAR=0,DIS=1 2101 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2109 TSF:MSG:READ,0-0-80,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2117 TSF:MSG:SEND,80-80-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 2129 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 4141 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:Living Room Fan Switch 4153 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.5 4161 TSF:MSG:SEND,80-80-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 4169 MCO:REG:REQ 4173 TSF:MSG:SEND,80-80-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 4239 TSF:MSG:READ,0-0-80,s=255,c=3,t=27,pt=1,l=1,sg=0:1 4245 MCO:PIM:NODE REG=1 4247 MCO:BGN:STP 6701 MCO:BGN:INIT OK,TSP=1 ▒&L▒TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1 Incoming change for sensor:1, New status: 1 M▒TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:▒2▒Ɂ▒▒▒ͽ▒▒brU▒▒.]X▒us: 1 54794 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:1 54800 TSF:MSG:ACK This is an ack from gateway 54806 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 96909 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:0 Incoming change for sensor:1, New status: 0 99350 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 99360 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:1 99366 TSF:MSG:ACK This is an ack from gateway 99371 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 101445 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=1,l=1,sg=0:1 101451 TSF:MSG:ACK This is an ack from gateway 101455 TSF:MSG:SEND,80-80-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 113451 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:0 Incoming change for sensor:1, New status: 0 118966 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:1 Incoming change for sensor:1, New status: 1 121210 TSF:MSG:READ,0-0-80,s=1,c=1,t=2,pt=0,l=1,sg=0:0 Incoming change for sensor:1, New status: 0
GW
0;255;3;0;9;MCO:BGN:STP 0;255;3;0;9;MCO:BGN:INIT OK,TSP=1 IP: 10.200.62.10 0;255;3;0;9;Attempting MQTT connection... 0;255;3;0;9;MQTT connected 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/0/0/18 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/11 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/255/3/0/12 0;255;3;0;9;Sending message on topic: /mysgw1-out/0/10/0/0/3 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 pm open,type:2 0 Incoming change for sensor:1, New status: 0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 0 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;TSF:MSG:ACK REQ 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;TSF:MSG:READ,80-80-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1 0;255;3;0;9;Sending message on topic: /mysgw1-out/80/1/1/0/2 Incoming change for sensor:1, New status: 1 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1 0;255;3;0;9;Message arrived on topic: /mysgw1-in/80/1/1/0/2 0;255;3;0;9;TSF:MSG:SEND,0-0-80-80,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:0
Whole code
#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_NODE_ID 80 #define MY_REPEATER_FEATURE #include <Arduino.h> #include <Adafruit_NeoPixel.h> #include <Ticker.h> #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #define RELAY_PIN 2 // Arduino Digital I/O pin number for relay #define BUTTON_PIN 3 // Arduino Digital I/O pin number for button #define CHILD_ID 1 // Id of the sensor child #define RGB_CHILD_ID 2 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 #define NUMPIXELS 1 #define PIXELPIN 4 #define BRIGHTNESS 10 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800); long RGB_values[3] = {0,0,0}; Bounce debouncer = Bounce(); int oldValue=0; bool state; MyMessage msg(CHILD_ID,V_LIGHT); void setup() { // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state = loadState(CHILD_ID); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); strip.begin(); strip.setBrightness(BRIGHTNESS); strip.show(); // Update the strip, to start they are all 'off' startupSequence(); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Living Room Fan Switch", "1.5"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_LIGHT); //present(RGB_CHILD_ID, S_RGB_LIGHT); } /* * Example on how to asynchronously check for new messages from gw */ void loop() { debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { send(msg.set(state?false:true), true); // Send new state and request ack back if (value == true){ colorSet(strip.Color(0, 255, 0)); // Green } else { colorSet(strip.Color(255, 255, 255)); // White } } oldValue = value; } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); send(msg.set(state?false:true)); } else if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID, state); if (state == true){ colorSet(strip.Color(0, 255, 0)); // Green } else { colorSet(strip.Color(255, 255, 255)); // White } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } void startupSequence(){ colorSet(strip.Color(255, 0, 0)); // Red delay(350); colorSet(strip.Color(255, 255, 0)); // Yellow delay(350); colorSet(strip.Color(0, 255, 0)); // Green delay(350); colorSet(strip.Color(0, 0, 0)); // Black delay(350); colorSet(strip.Color(0, 255, 0)); // Green delay(350); colorSet(strip.Color(255, 255, 255)); // White delay(350); colorSet(strip.Color(0, 0, 0)); // Black delay(350); colorSet(strip.Color(255, 255, 255)); // White } void colorSet(uint32_t color) { for (int i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, color); } strip.show(); }
-
RE: MQTT Gateway: Add a confirmation/acknowledgement to the publish topic upon setting via subscribe topic.
Changed to the following. Still no change. Still loops.
if (message.isAck()) { Serial.println("This is an ack from gateway"); send(msg.set(state?false:true), true); } else if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID, state); if (state == true){ colorSet(strip.Color(0, 255, 0)); // Green } else { colorSet(strip.Color(255, 255, 255)); // White } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }```
-
RE: MQTT Gateway: Add a confirmation/acknowledgement to the publish topic upon setting via subscribe topic.
@mfalkvidd that did not seem to work. It causes a loop where it sends the state back and forth, changing the value and switch state. This topic could be moved to troubleshooting if someone can do so as well.
void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID, state); send(msg.set(state?false:true), true); if (state == true){ colorSet(strip.Color(0, 255, 0)); // Green } else { colorSet(strip.Color(255, 255, 255)); // White } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
RE: AC Power and/or Relay interface
Adding the imgur album. https://imgur.com/a/XNz79
-
RE: AC Power and/or Relay interface
Np. I saw the "I am looking for a way to put an MySensors Relay actuator behind a wall switch." description. My project is a switch and relay in 1. Are you talking about just putting a MySensors node with a relay behind a working normal light switch?
-
RE: MQTT Gateway: Add a confirmation/acknowledgement to the publish topic upon setting via subscribe topic.
@mfalkvidd I did not think of that That should definitely work. I will give it a shot. Thanks!
Also for the record, I was thinking of a feature request globally. MySensors already does the acknowledgements in its own protocol, could be cool to do it with MQTT as well.
-
RE: AC Power and/or Relay interface
So I did this recently, I have two ESP8266 Wemos based switches and 2 MySensors based in production right now with more MySensors on the way. They encompass the following from AliExpress:
Arduino Pro Mini & NRF24L01
220/110V to 5V Transformer - https://www.aliexpress.com/item/Smart-Electronics-5V700mA-3-5W-Isolated-Switch-Power-Supply-Module-AC-DC-Buck-Step-down-Module/32529802796.html
WS2812B Single LED - https://www.aliexpress.com/item/10-100-pcs-WS2812B-LED-Individually-addressable-WS2811-IC-rgb-white-black-2812b-led-heatsink-10mm/32378187271.html
2 Small Tactile Buttons - https://www.aliexpress.com/item/100pcs-Tactile-Switch-Push-Button-Tactile-Pushbutton-4pin-DIP-6-6-10mm-for-LCD-Screen-Monitor/32693091694.html
Relay - https://www.aliexpress.com/item/Free-Shipping-10Pcs-5V-Low-Level-Trigger-One-1-Channel-Relay-Module-Interface-Board-Shield-for/32676400147.html
Dupont cables to make the switch and box separate. https://www.aliexpress.com/item/Free-shipping-Dupont-line-120pcs-20cm-male-to-male-male-to-female-and-female-to-female/32343840673.html3D Printed Switch and Rear Box
I created a switch and the box that goes in the wall in TinkerCAD. On the switch side, there is a little WS2812B led which i use to show states, and a little startup sequence to know its up and connected to the MySensors gateway. There are two buttons both behind the switch, one is pressed by the switch itself, the other is a reset switch which connects ground to the reset pin. This is in case it needs to be reset or something. I did this 2 piece approach for being able to take off the wallplate, pull out the switch, connect up the FTDI adapter and upload new code in the case of the MySensors nodes. For the ESP8266, those are OTA.
I am printing the latest version of the box and switch now, I will upload pics when they are done.
Here is the one in my garage, white means light is off (so you can find it in the dark), green is on. There is a red light coming from behind the switch which is the relay light, I dont care much in the garage so you can see it. On the inside ones, I used a small piece of heat shrink to cover it. Also, the pictures just do not do it justice at all, the light blurs out the camera and you cannot see the switch very well nor the power icon behind the LED.
-
MQTT Gateway: Add a confirmation/acknowledgement to the publish topic upon setting via subscribe topic.
Essentially right now, if i turn on a light/fan/binary/etc. over MQTT by using my in topic, it does what it is supposed to. But there is no output on the out topic to confirm to the Home Automation controller, (Home Assistant in this case), that the state was changed. I have to use optimistic mode, which does not help me if i want to know if the equipment is on/off. So after receive of a change via MQTT, send a update of the current status on the out topic.