Particle function question

how can I give Particle.function() an integer value instead of a String ?

Thanks :slight_smile:

You can’t. But you can use this:
https://docs.particle.io/reference/device-os/firmware/photon/#toint-

3 Likes

You can convert the arguments of the function to an int.

Example:

int myFunction(const char* args) {
    int myInt = atoi(args); // Convert args to an integer
    Serial.println(myInt*10); // Multiply myInt by 10 and print it to Serial
    return myInt; // return to see if args converted to the expected integer
}

In setup() you would have something like this:

Particle.function("myFunction", myFunction);

It’s good practice to use char arrays instead of String whenever possible.

3 Likes