Convert substring to integer

Hello

I know there are other posts detailing how this should work. Unfortunately I am missing something because they do not seem to work for me.

I am passing a numeric string e.g 109255125130 to my function, I am then using substring to parse out the elements for later usage (* this is not full code, just a snippet)

int ledToggle(String command) {
    
   String action=command.substring(0,1);
   String AAled=command.substring(1,3);       
   String red=command.substring(3,6);       
   String green=command.substring(6,9);
   String blue=command.substring(9);

I then need to convert the substring ‘part’ into an actual integer so

   int lednum = 0;
   lednum = AAled.toInt();

At this point (along with the remaining parts of the code), compiling completes without issue. no errors.

However, if I then attempt to use ‘lednum’ as a component in additional downstream processing such as

Particle.publish(“actionXX”, lednum, PRIVATE);

I get “invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]”; I do not understand the error, nor how to go about fixing it.

Can anyone put me out of my misery please?

Thanks
Tony

** please ignore the above request **. I just got it to work. The specific error from the original post relates to the an issue with particle.publish and is not the actual thing I am looking to do

Would be nice if you can post how you fixed it so others can benefit from your findings.

FYI: https://docs.particle.io/reference/device-os/firmware/photon/#particle-publish-

Particle publish expects a String, not an integer as far as I’m aware.

1 Like

quite so. please reference Json post payload particle.function for complete picture

lednum not declared as a global variable would not help!