Send a string as a value

  • Hi,

    is there a way to send a string as the value of a message:

    I would like to do that:

    String test = String(sRead1) + "-" + String(sRead2)+ "-" + String(sRead3); // result: "20.5-1011-2.5"

    I did not find a way to get "test" transformed (char, string,...) to get it sent. But interestingly this works:


    so I think there should be a way to get "test" transformed in a format which can be sent.

    Anyone any ideas?

    Many Thanks!

  • Admin

    You should avoid using String on embedded systems (thus we do not have any send for it).

    Have a look at strcpy.

  • do you have an example? Many Thanks!

  • Admin

    @Meister_Petz you can always do something like this:

    char Output[13];
    String OutStr = String(sRead1) + "-" + String(sRead2) + "-" + String(sRead3);

    but as @hek pointed out, try avoiding it where possible...

  • @tekka
    Many Thanks!
    I'd like to avoid it, but I'm not a developer and so my programing skills are limited ;-)

  • @Meister_Petz, you could simply write :

    String OutStr = String(sRead1) + "-" + String(sRead2) + "-" + String(sRead3);

  • Hero Member

    Or just use the character arrays with snprintf

  • many thanks! I know it's easy for you - unfortunately not for me. That's why I'm here. ;-)

Log in to reply

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.