I’m using a Particle function and Postman to enable/disable one of several motion sensors. The “args” parameter looks like this:
I’m using the
indexOf() function to find the colon and then use
toInt() to convert the zone number into an integer. All of this works great, but the issue I’m having is with the return value of
From the Particle documentation:
“Returns: long (If no valid conversion could be performed because the string doesn’t start with a integral number, a zero is returned.)”
If the function returns a 0 if the string doesn’t start with an integral number, and 0 is a valid integral number, how can the function differentiate between a valid 0 and the letter ‘A’? It seems the return value should be something like -1 to indicate an invalid integer instead of 0, since 0 is a valid integer.
Am I missing something obvious?