19.02.2021, 12:10
Add custom logic to the MQTT callbacks:
Using one topic for controlling multiple entities is bad system design. Each relay should have it's own topic for control if possible.
Code:
mclient.ON_CONNECT = function(res, ...)
log('mqtt connect status', res, ...)
if res then
mclient:subscribe('100')
else
mclient:disconnect()
end
end
mclient.ON_MESSAGE = function(mid, topic, payload)
if topic == '100' then
if payload == "C,1,1,\r\n" then
grp.write('0/0/1', true)
elseif payload == "C,1,0,\r\n" then
grp.write('0/0/1', false)
elseif payload == "C,2,1,\r\n" then
grp.write('0/0/2', true)
elseif payload == "C,2,0,\r\n" then
grp.write('0/0/2', false)
end
end
end
Using one topic for controlling multiple entities is bad system design. Each relay should have it's own topic for control if possible.