MQTT losing messages...

  • Hi guys,

    Long story cut short :

    I've had lots of "temporary gone bad nodes" since migrating from serial to mqtt.

    Nodes that are normally working fine but then stop responding (most annoying being the one driving the garage door motor 😱 i now keep a key anytime with me instead of just relying on openHab...). A reboot cures it.

    So i decided to design a simple logger with arduino + sd card + rtc.

    Beside that i am also designing an automatic cat flap locking node, so cats dont go out at night. As i dont want any rtc on that node, i rely on time supplied by controller with requestTime(). So here i am trying to understand how to send that request to controller via mqtt by sending publications...

    That's how i discovered that many publications are lost.

    What do you suggest to investigate further ? I might have reached my limits... 😬 some help would be welcome 👍

    Thanks a lot 😊

  • Hello

    can you tell us more about your mysensors architecture.
    see the chain of elements, hardware and software.

    your message is about : Mqtt 'mosquitto? - OpenHab - Arduino" uno?"

  • @JeeLet thanks a lot for your message

    You're right :

    • openhab 3
    • Raspberry Pi 3 MQTT gateway with Mosquitto
    • arduino nodes
    • nRF24 network

    TBH i don't know where to start, so difficult to point a finger...

  • here can be the beginning of an answer:

    "I don't know where to start," ... in a chain there are
    links, see which one is at fault

    "defective" since the migration from serial to mqtt" ...? what does it mean?

    I dialogue with you, but without really knowing, just to create a chain reaction of ideas 🙂

    maybe others have an idea !??

    Translated with (free version)

  • I'm not familiar with Hab. Does it include an MQTT broker or is Hab a client? If the latter, on what machine are you running the MQTT broker? I have put the broker in three places, 1) the same RPi as the MySensors MQTT Gateway, 2) a separate linux box, 3) the same linux box as Home Assistant. I haven't had any reason the think that MQTT had problems.

    Now if you have multiple nodes publishing to the same MQTT topic, you can and probably will see messages getting lost. This is because one node can overwrite another's message before the client picks up the message. Each node should be sending messages to its own topic.

    I like the cat door project 🙂


  • @JeeLet

    Thank you both 👍

    My Raspberry 3 does it all :

    • gateway with nrf24 module (standard one)
    • mysensors MQTT gateway
    • Mosquitto broker

    MQTT Explorer has been installed on my fav laptop and it helps seeing clearer.

    Nevertheless i cannot reproduce the errors.

    I have multiple points of view:

    • node : using arduino ide serial monitor
    • mysensors gateway: using tail log in a terminal window
    • openHab : using tail log in an internet explorer window
    • MQTT explorer : in its own window

    I can sent MQTT messages from different devices :

    • iOS openhab from my phone
    • openhab (basic UI) from an internet explorer window
    • MQTT explorer (messages can be made-up, very cool tool)
    • terminal window (linux laptop via ssh)

    The less reliable way of sending MQTT message is via terminal : after 2 to 10 succesfull messages it then stops working. At first, node receives messages and processes them (servo moves). But after a few messages, node doesn't receive anymore. MQTT Explorer shows the change of state of the topic but message doesn't go anyfurther... no other monitor show a change.

    @OldSurferDude i'm not sure i understand

    Each node should be sending messages to its own topic.

    Can the mysensor gateway subscribe to more than one topic (which is mysensors-in at the mo) ?

    Thanks a lot for helping me through 😊

  • @ben999

    Check out Serial Protocol

    I have four Arduinos. Each has a different MY_NODE_IDs (I use 130, 131, 132, 133). Each has four sensors: moisture, humidity, temperature, and voltage each of which has a CHILD_ID: CHILD_ID_MOISTURE is 0 , CHILD_ID_HUMIDITY is 1, CHILD_ID_TEMPERATURE is 2, CHILD_ID_VOLTAGE is 3.

    When an Arduino makes a measurement, it sends that measurement to a unique MQTT topic. In the case of the Arduino with MY_NODE_ID of 130 that is sending the moisture measurement, that MQTT topic is mysensors_out/130/0/1/0/35 and the message is [something like] 760 (35 is the value type)

    Similarly, when a controller sends a command to a device (Arduino), the topic is unique.

    If you have two actuators with the same MY_NODE_ID and CHILD_ID (MQTT topic) there would be confusion as to what you want each actuator to do. Likewise, if two sensors had the same MQTT topic, how would the controller know how to handle the data.

Log in to reply

Suggested Topics

  • 22
  • 1
  • 135
  • 10
  • 3
  • 5