Hey Particle Community,
So. C++ and strings make me kind of squirley. I just never get them right. So here’s a question that I need some help with, because my google-foo has turned up empty. I have a function, to send things out via twilio, and that requires sending some things to the webhook. How do I format strings to pass to Particle.publish properly? Originally I had all my things to pass like this:
Particle.publish("twilio", "{\"TWIL_ID\": \”XXXXXXXXXXXXXXXXXXXXXXXX\”},60,PRIVATE);
But that got pretty long.
So I know this “%s” is wrong, but using a char twilIDI[] = “XXXXX” etc. compiles, but then I think becomes incorrectly formatted.
void sendMessage(String msg)
{
char publishString[200];
String twilID = “XXXXXXXXXXXXXXXXXXXXXX”;
String twilToken = "XXXXXXXXXXXXXXXXXXXXXX";
String toNumber = “XXXXXXX”;
String fromNumber = “XXXXXXX”;
String message = msg;
sprintf(publishString,"{\"TWIL_ID\": %s,\"TWIL_TOKEN\": %s,\"TO_NUMBER\": %s, \"FROM_NUMBER\": %s, \"SPARK_EVENT_VALUE\": %s}",twilID,twilToken,toNumber,fromNumber,message);
Particle.publish("twilio",publishString,60, PRIVATE);
Serial.println("message sent!");
}
Suggestions?
Thanks!