Hi guys,
I’m trying to get variable and call functions from REST client (I’m using Postman, RestSharp on C# and cUrl too) but my Particle gives me timeout or results after 30+ seconds. A couple of months ago the same .ino works perfectly.
int photoresistor = A0; // This is where your photoresistor is plugged in. The other side goes to the "power" pin (below).
int power = A5; // This is the other end of your photoresistor. The other side is plugged into the "photoresistor" pin (above).
// The reason we have plugged one side into an analog pin instead of to "power" is because we want a very steady voltage to be sent to the photoresistor.
// That way, when we read the value from the other side of the photoresistor, we can accurately calculate a voltage drop.
int analogvalue; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
int dummyValue;
// Next we go into the setup function.
void setup() {
// First, declare all of our pins. This lets our device know which ones will be used for outputting voltage, and which ones will read incoming voltage.
pinMode(A0,INPUT); // Our photoresistor pin is input (reading the photoresistor)
pinMode(A5,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)
// Next, write one pin of the photoresistor to be the maximum possible, so that we can use this for power.
digitalWrite(A5,HIGH);
// We are going to declare a Particle.variable() here so that we can access the value of the photoresistor from the cloud.
Particle.variable("analogVal", &analogvalue, INT);
Particle.variable("dummyVal", &dummyValue, INT);
// This is saying that when we ask the cloud for "analogvalue", this will reference the variable analogvalue in this app, which is an integer variable.
// We are also going to declare a Particle.function so that we can turn the LED on and off from the cloud.
Particle.function("test",testFunction);
Particle.function("dummyPublish",dummyPublishFunction);
// This is saying that when we ask the cloud for the function "led", it will employ the function ledToggle() from this app.
}
// Next is the loop function...
void loop() {
// check to see what the value of the photoresistor is and store it in the int variable analogvalue
analogvalue = analogRead(photoresistor);
delay(200);
}
int dummyPublishFunction(String arg){
Particle.publish("Dummy","Nice and clean!");
return 0;
}
int testFunction(String command) {
if (command=="test") {
return 42;
}
else {
return -42;
}
}
There is nothing to see in your code that would cause the delay you see, and running on my device I can’t see that either, so there might be an issue with your connection or it was a temporary thing.