Inserting custom data into payload bytes

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

  • Mod

    @eporocrail it should be possible to use

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

    See for details.

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

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

  • Mod

    @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)

  • Thanks for your very fast reply!

    Up to the next step!

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

    Thanks a lot.

  • @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?

  • Mod

    @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)

  • @mfalkvidd

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


  • @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!

  • Mod

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

Log in to reply

Suggested Topics

  • 7
  • 5
  • 9
  • 6
  • 2
  • 79
  • 1
  • 1