Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Is it possible to request sensor status (via MQTT)?

Is it possible to request sensor status (via MQTT)?

Scheduled Pinned Locked Moved Troubleshooting
2 Posts 2 Posters 76 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joaoabsJ Offline
    joaoabsJ Offline
    joaoabs
    wrote on last edited by
    #1

    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" :blush: . Would there be any way of "asking" the sensors their statuses (via MQTT)?

    Cheers

    1 Reply Last reply
    0
    • BearWithBeardB Offline
      BearWithBeardB Offline
      BearWithBeard
      wrote on last edited by BearWithBeard
      #2

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

      1 Reply Last reply
      2
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      17

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular