REST API arguments - is there a better way?


will’s code worked for me but wow it’s not pretty.
Why can’t the parseInt() just work with any string? This seems like a popular problem with microcontrollers. When you want to send a string with many variables at the same time you would think that would be built-in.

Thanks all,


Because that’s not what that function is for; it’s meant only to parse out integers. It would be nice to have a function that was more general, but there doesn’t seem to be one yet. I prefer to do all my string manipulation on c-strings and use strtok or strtok_r to parse them, rather than using indexOf with String objects (due to possible heap fragmentation problems with Strings).


The clostet to that would be sscanf() but unfortunately doesn’t support floating point variables on a lot of embedded systems (including Particle).


I don’t understand your comment. Of course it’s meant only to parse out integers… from a stream string. Though this doesn’t work for a string passed in via the cloud functions like Particle.function() :frowning:


Sorry, I was reacting to your statement, “why can’t the parseInt() just work with any string”, and was thinking that, by “any” you were trying to parse things other than ints with it. I don’t know why it doesn’t work with String objects, other than String doesn’t inherit from Stream. It is too bad that there isn’t a string version that would do the same as parseInt(), but strtok() (in combination with atoi if you want integers) does do something similar, and is more general, in that you can parse any kind of string that has delimiters.