Hello everyone,
I’m a bit new here but i have a question about using the Particle photon with the CLI.
I looked over the example codes but i’m kinda stuck so any help would be appreciated (sorry if this was answered before).
So let’s say I want to build a thermostat:
I can use the // Particle.variable(“Temperature”, &temp_value, INT); // to get the current temperature reading and that works fine. But let’s say I have a variable called set point that I initialized to 25 degree C in set-up // int set_point = 25; //.
My question is how would I be able to modify set_point = value VIA the CLI since Particle.function accepts only strings. I don’t know if anything like a string 2 num would be possible then set_point = command; ??
I’m sure somebody will respond with the proper way to do this, but take a look below to get you started:
int publish_delay = 300000; // 5 minutes
void setup() {
// Register Particle Function to allow user to remotely Change the Publish Delay.
Particle.function("setDelay", setPublishDelay);
} // End setup
void loop() {
} // End loop
//Function to change the Publish Delay. Particle.functions take a string as an argument
int setPublishDelay(String command) {
publish_delay = ( command.toInt() * 60000 ); //send the # of MINUTES as an Argument to the setPublishDelay FUNCTION.
Particle.publish("Debug", "Publish Delay Updated", 300, PRIVATE);
}
You will see the Function listed after you select your Device in your console. https://console.particle.io/devices
In this example code, you would type the # of minutes into the function and press “Call” to update the publish_delay
This is the old syntax for a particle variable. Before you do anything, it's best to go to the docs (rather than looking at examples that might be old) for the latest info. The current way to do a variable is simpler:
Particle.variable("Temperature", temp_value);
The type is inferred by the type of your variable.
@Rftop showed you how to use a function, and convert the string to an intiger. If you want to call the function using the CLI, you just do this,
particle call <the name of your device here> setDelay <put the value you want to send here>