Particle.Publish string() not working

Hey Everyone -

First post, so please forgive any hiccups!

Writing some code for an argon, and having a heck of a time trying to get a particle event to publish. Here is the relevant excerpt from the code:

//make the connection
int response = httpsClientConnection(httpRequestContent, 0, NULL);
                    
//TEMPORARY TEST - send event to particle
Particle.publish("FMToken Contents", string(response), PRIVATE));

I am using the Glowfi.sh HTTPS client library, and setting the response equal to an int variable. Then, I try to publish an event with that value, making sure to convert to string, but I continually get these compile errors for the publish line:

  • no matching function for call to ‘std::__cxx11::basic_string<char>::basic_string(int&)’
  • invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]

I’ve used the format of
"Particle.publish("Title", string(variable), PRIVATE)
before with no issues. Any ideas what’s tripping me up here?

It is much better to avoid using String object and instead using a c char array string.

Use snprintf() to format a char array and pass that to Particle.publish();

Shouldn’t string(response) be String(response, DEC)?

2 Likes

I agree with @armor on avoiding String objects but for your problem at hand, you should write String(response) with a capital S (the DEC format info should not be requierd as decimal is the default).