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. Inserting custom data into payload bytes

Inserting custom data into payload bytes

Scheduled Pinned Locked Moved Development
12 Posts 2 Posters 2.1k 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.
  • eporocrailE Offline
    eporocrailE Offline
    eporocrail
    wrote on last edited by
    #1

    I installed the ESP8266 MQTT gateway. When I close a switch on a NANO client I see the message being published on Mosquitto. Thus sofar so good.
    What I am looking for is a description of how to insert BYTE type data into several payload bytes.
    It would be most helpful to be able to construct in the Arduino sketch the complete message in accordance with the protocol description, coded by myself.

    As far as I can understand the MyMessage.h and MyMessage.ccp it should be possible. But my knowledge is not sufficient to come up with a procedure myself.

    mfalkviddM 1 Reply Last reply
    0
    • eporocrailE eporocrail

      I installed the ESP8266 MQTT gateway. When I close a switch on a NANO client I see the message being published on Mosquitto. Thus sofar so good.
      What I am looking for is a description of how to insert BYTE type data into several payload bytes.
      It would be most helpful to be able to construct in the Arduino sketch the complete message in accordance with the protocol description, coded by myself.

      As far as I can understand the MyMessage.h and MyMessage.ccp it should be possible. But my knowledge is not sufficient to come up with a procedure myself.

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @eporocrail it should be possible to use

      MyMessage& set(void* payload, uint8_t length);
      

      See https://www.mysensors.org/download/sensor_api_20#message-manipulation for details.

      1 Reply Last reply
      0
      • eporocrailE Offline
        eporocrailE Offline
        eporocrail
        wrote on last edited by
        #3

        Thanks for your reaction!!!
        I am going to experiment with it and post proceedings later!

        1 Reply Last reply
        1
        • eporocrailE Offline
          eporocrailE Offline
          eporocrail
          wrote on last edited by
          #4

          I succeeded to transfer one single byte. It is not clear to me how I can construct a message in the payload which contains ten bytes.
          The normal concatenation seems not to work.
          I tried several things but no luck.

          mfalkviddM 1 Reply Last reply
          0
          • eporocrailE eporocrail

            I succeeded to transfer one single byte. It is not clear to me how I can construct a message in the payload which contains ten bytes.
            The normal concatenation seems not to work.
            I tried several things but no luck.

            mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by mfalkvidd
            #5

            @eporocrail I think you can simply use byte myByteArray[10] and set each byte (0-9) to your payload. Then call message.set(myByteArray, 10)

            1 Reply Last reply
            0
            • eporocrailE Offline
              eporocrailE Offline
              eporocrail
              wrote on last edited by
              #6

              Thanks for your very fast reply!

              Up to the next step!

              1 Reply Last reply
              0
              • eporocrailE Offline
                eporocrailE Offline
                eporocrail
                wrote on last edited by
                #7

                @mfalkvidd It works!
                Bytes put into the message are transferred in Hex. They show up in the Mosquitto toppic!

                Thanks a lot.

                1 Reply Last reply
                0
                • eporocrailE Offline
                  eporocrailE Offline
                  eporocrail
                  wrote on last edited by
                  #8

                  @mfalkvidd

                  I again need your advice

                  } void loop() { data1 = data1 + 1; bericht[1] = data1; send(msg.set(data1)); send(msg.set(bericht, 1)); }

                  data1 is transferred to Mosquito with a changing value.
                  bericht[1] is transferred with the originally assigned value.
                  it is not updated to the new value.
                  what could be causing this?

                  mfalkviddM 1 Reply Last reply
                  0
                  • eporocrailE eporocrail

                    @mfalkvidd

                    I again need your advice

                    } void loop() { data1 = data1 + 1; bericht[1] = data1; send(msg.set(data1)); send(msg.set(bericht, 1)); }

                    data1 is transferred to Mosquito with a changing value.
                    bericht[1] is transferred with the originally assigned value.
                    it is not updated to the new value.
                    what could be causing this?

                    mfalkviddM Offline
                    mfalkviddM Offline
                    mfalkvidd
                    Mod
                    wrote on last edited by
                    #9

                    @eporocrail arrays start numbering for zero. So send(bericht, 1) will send the first byte of bericht, but data1 was written to the second byte.

                    Either use bericht[0]=data1 (if you want to send only one value) or use send(bericht, 2) if you want to send two values (bericht[0] and bericht[1] together)

                    1 Reply Last reply
                    0
                    • eporocrailE Offline
                      eporocrailE Offline
                      eporocrail
                      wrote on last edited by
                      #10

                      @mfalkvidd

                      Somebody has to make that mistake again!
                      This time it was me!

                      Thanks.

                      1 Reply Last reply
                      1
                      • eporocrailE Offline
                        eporocrailE Offline
                        eporocrail
                        wrote on last edited by
                        #11

                        @mfalkvidd

                        I did some tests.
                        I put a byte counter I a loop without delay.
                        The nano was able to publish every fourth number. So the network is functioning but for not a very high speed requirement.

                        I did the same with a MQTT client on a Wemos D1 mini module. The difference in speed was dramatic. No gaps between numbers and much faster.

                        Because of the envisioned use for controlling a model railroad track layout I decided to go for the higher performance of the Wemos with all negative consequences as far s complexity of decoder composition is concerned.

                        Thanks for the support!

                        mfalkviddM 1 Reply Last reply
                        1
                        • eporocrailE eporocrail

                          @mfalkvidd

                          I did some tests.
                          I put a byte counter I a loop without delay.
                          The nano was able to publish every fourth number. So the network is functioning but for not a very high speed requirement.

                          I did the same with a MQTT client on a Wemos D1 mini module. The difference in speed was dramatic. No gaps between numbers and much faster.

                          Because of the envisioned use for controlling a model railroad track layout I decided to go for the higher performance of the Wemos with all negative consequences as far s complexity of decoder composition is concerned.

                          Thanks for the support!

                          mfalkviddM Offline
                          mfalkviddM Offline
                          mfalkvidd
                          Mod
                          wrote on last edited by
                          #12

                          @eporocrail very nice, great work! Thanks for reporting back.

                          You might know this already, but it is possible to run the Wemos at 160MHz instead of default 80MHz. Not sure if you need it or if it helps, but it might be good to know. Just select the higher frequency in the Tools menu in Arduino IDE.

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


                          19

                          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