Send a string as a value
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:
so I think there should be a way to get "test" transformed in a format which can be sent.
Anyone any ideas?
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!
@Meister_Petz you can always do something like this:
char Output; 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...
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()));
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.