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"
    gw.send(msg1.set(test));
    

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

    gw.send(msg1.set("20.5-1011-2.5"));
    

    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);
    OutStr.toCharArray(Output,13);
    gw.send(msg.set(Output));
    

    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);
    gw.send(msg.set(OutStr.c_str()));
    

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