When consuming a thinger event, i.e. switch on/off toggle and logic is applied that may run several minutes, all other calls to the Client Lib is blocked until the running process completes.
The example in my case, is that I have an irrigation system that spans across 16 valves - when I toggle the program to tun, each valve is opened for about 15 minutes, whereafter the next is activated. This means that the program cycle will run for about 240 minutes. During this time any other calls to the Client fail, such as data collections of sensors.
- Can anyone recommend a implementation to avoid such a scenario?
- How can I update other “things” as a progress through each valve - i.e. I have a switch in the dashboard for each valve - but I want to set its value as I progress as those items in the dashboard does not automatically refresh like other widgets.
Here with a sample of my code:
thing["program_switch"] <<[](pson & in)
{
if (in.is_empty())
{
in = (bool) vProgIndicator;
}
else
{
vProgIndicator = in;
if (vProgIndicator == 1)
{
//Start Pump
digitalWrite(relay1, LOW);
int micro = 1000000;
usleep(micro*(vProgTime*60));
digitalWrite(relay2, LOW);
vProgProgress = vProgProgress + 1;
usleep(micro*(vProgTime*60));
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW);
vProgProgress = vProgProgress + 1;
usleep(micro*(vProgTime*60));
digitalWrite(relay3, HIGH);
digitalWrite(relay4, LOW);
vProgProgress = vProgProgress + 1;
usleep(micro*(vProgTime*60));
digitalWrite(relay4, HIGH);
digitalWrite(relay5, LOW);
vProgProgress = vProgProgress + 1;
usleep(micro*(vProgTime*60));
digitalWrite(relay5, HIGH);
//Stop Pump
digitalWrite(relay1, HIGH);
//Continue with the rest of the relays here...
}
else
{
vProgProgress = 0;
initRelays();
}
vProgIndicator = 0;
}
};