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. Development
  3. MQTT RETAIN messages work a little strangely

MQTT RETAIN messages work a little strangely

Scheduled Pinned Locked Moved Development
5 Posts 2 Posters 79 Views 2 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.
  • C Offline
    C Offline
    Clone Tv
    wrote on last edited by
    #1

    MQTT RETAIN messages work a little strangely. The first ones always come and are recorded by the mosquito server, but all subsequent messages do not reach and are not recorded by the server .. The RETAIN flag is naturally set.

    YveauxY 1 Reply Last reply
    0
    • C Clone Tv

      MQTT RETAIN messages work a little strangely. The first ones always come and are recorded by the mosquito server, but all subsequent messages do not reach and are not recorded by the server .. The RETAIN flag is naturally set.

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @Clone-Tv what exactly is your issue? Is it with the mosquitto MQTT broker, the MQTT mysensors gateway, or...?

      http://yveaux.blogspot.nl

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Clone Tv
        wrote on last edited by
        #3

        Yes, I am using the mosquitto MQTT broker, but the problem is most likely with the mysensors MQTT gateway. On Mosquito, I am able to write a packet with the retained flag from the console, and it works.

        YveauxY 1 Reply Last reply
        0
        • C Clone Tv

          Yes, I am using the mosquitto MQTT broker, but the problem is most likely with the mysensors MQTT gateway. On Mosquito, I am able to write a packet with the retained flag from the console, and it works.

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @Clone-Tv Could you post your sketch, gateway log and which hardware you're using?

          E.g. the default MQTT gateways don't set MY_MQTT_CLIENT_PUBLISH_RETAIN, so the stack behaves differently when set (https://github.com/mysensors/MySensors/blob/6c4b8055f729d1582b52068e3e858b77803a18b3/core/MyGatewayTransportMQTTClient.cpp#L129)

          http://yveaux.blogspot.nl

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Clone Tv
            wrote on last edited by Clone Tv
            #5

            I do not use signed messages, so I used the Signed flag in the MySensors packet header to implement selective MQTT retain state.

            Gateway is ESP2866 - no specific code.
            Code send from client:

            template<typename T>
            void reportMsg(const uint8_t & id, const mysensors_data_t & tag, const T & val, const bool retain) {
                MyMessage msg(id, tag);
                msg.setSigned(retain);
                send(msg.set(val), true);
            }
            

            Lite patch MyGatewayTransportMQTTClient.cpp:

            bool gatewayTransportSend(MyMessage &message) {
               ...
               bool retain = message.getSigned();
               message.setSigned(false);
               ....
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            28

            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