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. Personalize the MQTT topics

Personalize the MQTT topics

Scheduled Pinned Locked Moved Development
7 Posts 3 Posters 94 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.
  • D Offline
    D Offline
    DenisJ
    wrote on last edited by
    #1

    Hi there all.
    I finally finish to make work my first node and I'm very happy that it's work greate.

    I just want to ask if it's possible to personalize the MQTT topics.
    I mean, if it's possible in the GATEWAY code to intercept the NodeID, SensorID and value
    and make a personalized topics in order to send it to MQTT broker.

    I ask this because I make just a unique node and in my MQTT
    it's already a lot of confusion...
    There is a lot of number that I must translate every time I take a look.

    What I would like is... use the MQTT code in order to make the broker connection,
    stop the default update of topics, intercept the NodeID/SensorID/Value and give e personalized name.

    Thanks all in advance
    Denis

    YveauxY 1 Reply Last reply
    0
    • D DenisJ

      Hi there all.
      I finally finish to make work my first node and I'm very happy that it's work greate.

      I just want to ask if it's possible to personalize the MQTT topics.
      I mean, if it's possible in the GATEWAY code to intercept the NodeID, SensorID and value
      and make a personalized topics in order to send it to MQTT broker.

      I ask this because I make just a unique node and in my MQTT
      it's already a lot of confusion...
      There is a lot of number that I must translate every time I take a look.

      What I would like is... use the MQTT code in order to make the broker connection,
      stop the default update of topics, intercept the NodeID/SensorID/Value and give e personalized name.

      Thanks all in advance
      Denis

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

      @DenisJ that should be possible, although mysensors does not implement it.

      What you could do is use the MQTT MySensors gateway as-is, and use a service on top, running somewhere else, that subscribes to the mysensors MQTT topics, 'decodes' them and republishes the data under different, understandable topics to the MQTT broker.

      This way you are not deviating from the MySensors gateway implementation (e.g. when updates are released) and you do not have to modify & reflash your gateway each time a node is added.

      I personally use node-red for the decoding, but any other 'programming' tool with MQTT access should work.

      http://yveaux.blogspot.nl

      1 Reply Last reply
      1
      • D Offline
        D Offline
        DenisJ
        wrote on last edited by
        #3

        Thanks a lot Yveaux... it's just what I work to from about 2 hours :-)
        I'll split all sensors in Node-Red with a new topic name.
        I use something like:

        /*
        id SensGarag: 11
        id SensCame1: 
        id SensCame2: 
        id SensCame3: 
        id SensCucin: 
        id SensFuori: 
        id SensSalon: 
        id SensSerra: 
        type Temp : 51
        type Hum  : 52
        type Press: 53
        */
        
        // sensor id (topic:MySensors-out/xx/)
        var parts = msg.topic.split("/");
        id   = parts[1];
        type = parts[2];
        

        Thanks a lot again
        Denis

        YveauxY 1 Reply Last reply
        0
        • D DenisJ

          Thanks a lot Yveaux... it's just what I work to from about 2 hours :-)
          I'll split all sensors in Node-Red with a new topic name.
          I use something like:

          /*
          id SensGarag: 11
          id SensCame1: 
          id SensCame2: 
          id SensCame3: 
          id SensCucin: 
          id SensFuori: 
          id SensSalon: 
          id SensSerra: 
          type Temp : 51
          type Hum  : 52
          type Press: 53
          */
          
          // sensor id (topic:MySensors-out/xx/)
          var parts = msg.topic.split("/");
          id   = parts[1];
          type = parts[2];
          

          Thanks a lot again
          Denis

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

          @DenisJ nice!
          Btw. @tbowmo created a nice set of node-red nodes to de- and encode MySensors messages. Maybe they can be of good use to you.

          http://yveaux.blogspot.nl

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisJ
            wrote on last edited by
            #5

            I have try to install it but node-red give me some error.
            But I have make a function that have a tabel that personalize all topics.
            f63850b0-813f-4aa3-aff0-9f9f85ca6e8c-image.png
            So I'll make all my future sensors in this mode.

            Thanks again
            Denis

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sindrome73
              wrote on last edited by
              #6

              I'm interested, can you share some more info on this feature ??

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DenisJ
                wrote on last edited by DenisJ
                #7

                Practically I receive the MQTT topics from the MySensors Gateway.
                Then in Node-Red I have make a function that translate the MySensors MQTT topics in a personalized MQTT topics,
                in order to have clear names of the sensors value.

                In Node-Red you make a flow like this:
                d6af473c-7ae1-4977-834e-04fcf8f98b26-image.png

                Then in the function node you make something like this... but personalized:

                // add timestamp to every sensor reads
                var dt = new Date();
                var hh = dt.getHours();
                var mm = dt.getMinutes();
                var ss = dt.getSeconds();
                var yy = dt.getFullYear();
                var mo = dt.getMonth() + 1; // want 1 more
                var dd = dt.getDate();
                //var daynum = date.getDay();
                timeST = (dd < 10 ? "0" : "") + dd + "-" + (mo < 10 ? "0" : "") + mo + "-" + yy + 
                  " " + (hh < 10 ? "0" : "") + hh + ":" + (mm < 10 ? "0" : "") + mm + ":" + (ss < 10 ? "0" : "") + ss;
                
                /* sensors ID
                id SensGaraj: 11
                id SensCame1: 
                id SensCame2: 
                id SensCame3: 
                id SensCucin: 
                id SensSerra: 12
                id SensFuori: 
                id SensSalon: 
                
                type Temp  : 51
                type Hum   : 52
                type Press : 53
                type BatVol: 54
                type BatLev: 255 
                */
                
                ret = 0; // send the return or not
                
                // sensor id (topic:MySensors-out/xx/) 
                var parts = msg.topic.split("/");
                id   = parts[1];
                type = parts[2];
                val  = msg.payload;
                
                if (id == 11 ){sname = "SensGaraj";ret = 1;}
                if (id == 12 ){sname = "SensSerra";ret = 1;} 
                // if etc...
                
                if (ret == 1){
                    if (type == 51 ){stype = "Temp"; }
                    if (type == 52 ){stype = "Hum";}
                    if (type == 53 ){stype = "Press";}
                    if (type == 54 ){stype = "BattVol";}
                    if (type == 255){stype = "BattLev";}
                    msg = {}; //initialize msg object
                    msg.measurement = "sensors"; // tabella/file > influxdb
                    msg.topic = "MySensors/" + sname + "/" + stype;
                    msg.payload = {value: val, timeST: timeST}
                    node.status({fill:"green",shape:"ring",text:sname});
                    return msg;
                }
                //////////////////////////////////////////////////////////////
                

                If you need more help just let me know :-)

                Denis

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


                38

                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