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!
-
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[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()));
-
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.
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
Sending offset to node
Development • 25 days ago • bsl88k 21 days ago -
LAN8720A - will mysensors work with this module
Development • 13 Nov 2024, 17:06 • Marcin 15 Nov 2024, 10:59 -
Counting Incoming and Outgoing Messages from a Gateway
Development • 10 Dec 2024, 21:57 • Trand 14 Dec 2024, 20:23 -
[mysensors] Not a valid message: invalid literal for int() with base 10: '\x00\x000'
Development • 18 Sept 2024, 20:34 • kiesel 20 Sept 2024, 08:28 -
MQTT GW on ESP8266 supporting SSL/TLS?
Development • 4 Jun 2024, 10:21 • bgunnarb 27 Jun 2024, 13:53