Newb Questions

Hello,

I have been experimenting with Yun and Mega and Uno as well as Particles Photon and Electron.
I was thinking of making a reboot box to reboot equipment at remote sites and I am curious if there is a cleaner and simpler way to code it.

currently I can send a curl command to the Photon like this:
curl https://api.particle.io/v1/devices/devicename/outlet1 -d access_token=accesstoken -d params="outlet1 reboot" and it will pulse a relay as desired. But if I want to scale it to do 8 outlets is there a optimal way to code that? I imagined just doing a curl with the params="outletx on" and the code can can determine what pin to trigger based on the outlet number passed in the params?

Sorry if it doesn't make very good sense. I'm getting over the flu and have a hard time wording this in a coherent way. Thanks in advance for any suggestions.

int outlet1 = D0;

void setup() {

pinMode(outlet1, OUTPUT);

Particle.function("outlet1",OutletToggle);
digitalWrite(outlet1, LOW);

}

void loop() {
// no looping, we're doing remote calls here!
}

int OutletToggle(String command) {
if (command=="outlet1 on") {
digitalWrite(outlet1,HIGH);
return 1;
}
else if (command=="outlet1 off") {
digitalWrite(outlet1,LOW);
return 0;
}
else if (command=="outlet1 reboot") {
digitalWrite(outlet1,HIGH);
delay(5000);
digitalWrite(outlet1,LOW);
}
else {
return -1;
}
}

Your program can only run one command. Then it freezes.

aarg:
Your program can only run one command. Then it freezes.

I can keep adding else if statements for command=="outlet2 reboot" etc however I was curious if it could be coded in such a way that it uses the params="" from the curl to tell it which pin to operate without defining each one with else if statements.

mikrologic:
I can keep adding else if statements for command=="outlet2 reboot" etc

... until it reaches the end of those, then it will freeze.

aarg:
... until it reaches the end of those, then it will freeze.

I am not sure what your point is exactly. The system responds to my curl commands whenever I send them since I have: Particle.function("outlet1",OutletToggle);

My question is more about a clean way of controlling multiple outlets. I have made it work by literally putting in 3 ifs (on,off,reboot) per outlet. However my question was more about if it possible to pass the data received from the params in such a way that I can have a single on, off and reboot and it will use the outletx from the first part of the param to define what outlet to control.

FYI:

Particle.function()

Expose a function through the Cloud so that it can be called with POST /v1/devices/{DEVICE_ID}/{FUNCTION}.

I am not sure what your point is exactly. The system responds to my curl commands whenever I send them since I have: Particle.function("outlet1",OutletToggle);

Your Arduino does?

If you are talking about some other device, their forum is more appropriate.

mikrologic:
I am not sure what your point is exactly. The system responds to my curl commands whenever I send them since I have: Particle.function("outlet1",OutletToggle);

Once you have executed a reboot, you never want to do it again?

PaulS:
Your Arduino does?

If you are talking about some other device, their forum is more appropriate.

Its a conceptual question. My question is valid on Arduino or Particle. If people could get past the example and grasp the question and comment on that vs perceived issues it would be helpful.

aarg:
Once you have executed a reboot, you never want to do it again?

After I execute any of the commands I can repeat them at will with no issue. But it doesn't matter as my original question is still not answered.

mikrologic:
Its a conceptual question. My question is valid on Arduino or Particle. If people could get past the example and grasp the question and comment on that vs perceived issues it would be helpful.

The question does not relate to the Arduino platform. It relates to the Particle/Photon platform. (A Photon is not an Arduino.)
An Arduino is a different device and will freeze as mentioned. Try asking your question in an appropriate forum.

For those following this thread, here's more info on the Particle/Photon:-
https://www.twilio.com/blog/2015/10/getting-started-with-the-particle-photon-iot-for-under-20.html