2

I have everything working wonderfully but I want to accomplish one more thing and I'm not sure how to go about it.

Part one to this question:

Under command=="loops" I have a delay() function. I want to be able to sent this time from the dashboard or url. Example would be… (written in php action of CURL):

$url =  “https://api.particle.io/v1/devices/".$my_device."/".$zone_name."?access_token=”.$my_token;

Would my URL be changed to

$url = “https://api.particle.io/v1/devices/".$my_device."/".$zone_name."?dealy=100&access_token=”.$my_token;

If so how do I assign the var to my delay?

Part 2 of the question is, I don’t know if delay is the right option. I remember reading something about delay causing a lockout and the device cant do anything while this is going on. If this is the case this will not work as I will have other functions that will trigger other events. What other functions do I have to solve this problem?

int zoneone = D5;
int zonetwo = D6;
int zonethree = D7;
int zonefour = D8;

void setup() {

// define pine as output high/low not digital read pinMode(zoneone, OUTPUT); pinMode(zonetwo, OUTPUT); pinMode(zonethree, OUTPUT); pinMode(zonefour, OUTPUT);

// creates the webhook actions Particle.function("zoneone",zones_one); Particle.function("zonetwo",zones_two); Particle.function("zonethree",zones_three); Particle.function("zonefour",zones_four);

// sets everything to off just to make sure we are in the right state digitalWrite(zoneone, LOW); digitalWrite(zonetwo, LOW); digitalWrite(zonethree, LOW); digitalWrite(zonefour, LOW);

}

void loop() { // Nothing to do here }

// zone one action int zones_one(String command) {

if (command=="on") {
    digitalWrite(zoneone,HIGH);
    return 1;
}
 if (command=="loops") {

    digitalWrite(zoneone,HIGH);

// need to change this to a delay(var); delay(75); digitalWrite(zoneone,LOW); return 2; } else if (command=="off") { digitalWrite(zoneone,LOW); return 0; } else { return -1; } }

// zone two action int zones_two(String command) {

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

}

// zone three action int zones_three(String command) {

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

}

// zone four action int zones_four(String command) {

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

}

Bence Kaulics
  • 7,783
  • 8
  • 41
  • 90
Kelly
  • 21
  • 1
  • Where does your code call the zone functions? You should pass the delay just as you pass zone_name and command to your code. – Bence Kaulics Dec 28 '20 at 12:44

0 Answers0