How is a Particle.function called?

I’m an experienced microcontroller programmer playing with an electron board.

Didn’t take long to get the led blinking and play with that for a while. The second example uses the particle.function call to get a message from somewhere, but I seem to have missed where this message comes from.

Following the example, I have

Particle.function("led",ledToggle);

and the function ledToggle

int ledToggle(String command) {
    /* Particle.functions always take a string as an argument and return an integer.
    Since we can pass a string, it means that we can give the program commands on how the function should be used.
    In this case, telling the function "on" will turn the LED on and telling it "off" will turn the LED off.
    Then, the function returns a value to us to let us know what happened.
    In this case, it will return 1 for the LEDs turning on, 0 for the LEDs turning off,
    and -1 if we received a totally bogus command that didn't do anything to the LEDs.
    */

    if (command=="on") {
        digitalWrite(led1,HIGH);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(led1,LOW);
        return 0;
    }
    else {
        return -1;
    }
}

I’m guessing it takes messages like “led on” or “led off,” but what sends this message? Somewhere here on the site perhaps?

Have a look:

https://docs.particle.io/tutorials/hardware-projects/hardware-examples/photon/#control-leds-over-the-39-net

1 Like

Oh, wow. Instructions!

Thanks. I knew I missed something.

Ok. I found my device id, but where do I find the access token?

Doesn’t seem to be ICCID or IMEI from the Particle Console.

The Docs Moors7 linked to shows you how to toggle the led from your Particle Console.

1 Like

Have a look :wink:

https://docs.particle.io/tutorials/developer-tools/build/photon/#account-information

1 Like

And, for anybody googling…

You just click the gear icon in the bottom left of the Build screen.