Concatenation of strings

Everything about programming the platform and using the Waspmote API
Post Reply
Ssegurap
Posts: 14
Joined: Mon Sep 04, 2017 4:43 am
Company: Enextgia S.A.S

Concatenation of strings

Post by Ssegurap » Tue Sep 05, 2017 5:51 am

Hi,

I´m trying to build an AT command string using the waspmote IDE. Im porting Arduino code that uses a string concatenation operator +=. Is there support for anything like this in the waspmote API? For example, here is my Arduino code:

// TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
ser.println(cmd);

Thanks!

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Concatenation of strings

Post by libelium-dev » Tue Sep 05, 2017 8:51 am

Hi,

Some our libraries create AT string, you can take a look at the GPRS, 3G or 4G libraries. For example the 3G library has sendATCommand() funtion to send AT commands

Code: Select all

_3G.sendATCommand("+CPIN");
USB.println(_3G.buffer_3G);
To format the string you can use snprintf() function, here you can see how use this function
http://www.libelium.com/development/was ... d-strings/

Regards

Carlosrod298
Posts: 2
Joined: Fri Aug 23, 2019 9:47 pm
Company: Unicauca

Re: Concatenation of strings

Post by Carlosrod298 » Mon Aug 26, 2019 5:19 pm

Hello!

You can declare your string like this

// example of body for POST request
char body[300];
// example of body for POST request
char ArrayVars[30];
char float_str[10];

//ID
snprintf( body, sizeof(body), "{\"ID\":%s ,",LibeliumID);
//Radiation
dtostrf( radiation, 1, 3, float_str); //Convert float to string
snprintf(ArrayVars,sizeof(ArrayVars),"\"RAD\":%s }",float_str);
strcat(body,ArrayVars);

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Concatenation of strings

Post by libelium-dev » Tue Aug 27, 2019 8:30 am

Hi,

Thanks for your contribution to the forum.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest