Is it possible to request sensor status (via MQTT)?
-
Hi,
I'm testing a dual-SSR node connected to 220v (therefore, never sleeping).
The node data is the following:Node ID: 80 Childs: * HTU21 TEMP: 20 * HTU21 HUM: 40 * SSR1: 10 * SSR2: 11
Following the MySensors API structure
Node-ID / Child-ID / Command / Ack / Type / Payload
I believe I'm able to set a relay via MQTT with the command line command:
mosquitto_pub -d -h 192.168.2.180 -u myuser -P mypass -t mysensors-in/80/10/1/1/2 -m "0"
and get (what I believe its the confirmation):
pi@raspberrypi:~ $ mosquitto_sub -h 192.168.2.180 -p 1883 -u myuser -P mypass -t mysensors-out/80/# -d Client mosqsub|5920-raspberryp sending CONNECT Client mosqsub|5920-raspberryp received CONNACK (0) Client mosqsub|5920-raspberryp sending SUBSCRIBE (Mid: 1, Topic: mysensors-out/80/#, QoS: 0) Client mosqsub|5920-raspberryp received SUBACK Subscribed (mid: 1): 0 Client mosqsub|5920-raspberryp received PUBLISH (d0, q0, r0, m0, 'mysensors-out/80/10/1/1/2', ... (1 bytes)) 0
I don't have at the moment anything connected to the relay to confirm if its switching or not, so I was trying to use the "request" command to request the child statuses.
Something like:
mosquitto_pub -d -h 192.168.2.180 -u myuser -P mypass -t mysensors-in/80/10/2/1/2 -m ""
Even trying to request temperature statuses:
pi@raspberrypi:~/mysensors-back $ mosquitto_pub -d -h 192.168.2.180 -u myuser -P mypass -t mysensors-in/80/20/2/1/0 -m ""
but I'm not getting anything:
Client mosqsub|6459-raspberryp received PUBLISH (d0, q0, r0, m0, 'mysensors-out/80/20/2/1/0', ... (0 bytes)) Client mosqsub|6459-raspberryp received PUBLISH (d0, q0, r0, m0, 'mysensors-out/80/10/2/1/2', ... (0 bytes))
I've read in the API documentation that the "request" command is "usually from an actuator destined for controller" so I'm wondering if it would be just "usually" or definitely "uniquelly"
. Would there be any way of "asking" the sensors their statuses (via MQTT)?
Cheers
-
"Usually" is the correct term. You can request whatever you want using MQTT, but you need to handle the response manually inside the
receive()
function. This isn't an automatic internal process like the echo or ack response.void receive(const MyMessage &message) { if (message.getCommand() == C_REQ) { switch (message.getSensor()) { case 10: // Send SSR 1 state break; case 11: // Send SSR 2 state break; case 20: // Send temperature sensor value break; case 40: // Send humidity sensor value break; default: break; } } }
Note: It's best to not send a message from within
receive()
as it can cause all sorts of weird stuff, including recursive loops. Preferably, you'd set a flag and handle everything else in the main loop.
Suggested Topics
-
Day 1 - Status report
Announcements ā¢ 23 Mar 2014, 22:45 ā¢ hek 24 Mar 2014, 20:12 -
Forum Search not working?
Troubleshooting ā¢ 4 Oct 2023, 23:33 ā¢ Gibber 2 Sept 2024, 20:28 -
JSN SR04T - Temperature Influencing Readings
Troubleshooting ā¢ 6 Sept 2019, 07:51 ā¢ Timbergetter 4 days ago -
Can not compile MySensors on esp8266
Troubleshooting ā¢ 24 Aug 2024, 15:35 ā¢ TheoL 29 Aug 2024, 20:47 -
Getting system time from the controller
Troubleshooting ā¢ 27 Feb 2025, 01:39 ā¢ dpcons 29 days ago -
JSN-SR04T-V3.0 Coax cable extended
Troubleshooting ā¢ 13 days ago ā¢ bocalexandru 11 days ago