Skip to content

Commit da89ded

Browse files
committed
Merge remote-tracking branch 'mysensors/master'
2 parents f35aad0 + df5e379 commit da89ded

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

examples/IrrigationController/IrrigationController.ino

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ Contributed by Jim ([email protected]) with much contribution from Pete (p
100100

101101
#define NUMBER_OF_VALVES 8 // Change this to set your valve count up to 16.
102102
#define VALVE_RESET_TIME 7500UL // Change this (in milliseconds) for the time you need your valves to hydraulically reset and change state
103+
#define VALVE_TIMES_RELOAD 300000UL // Change this (in milliseconds) for how often to update all valves data from the controller (Loops at value/number valves)
104+
// ie: 300000 for 8 valves produces requests 37.5seconds with all valves updated every 5mins
103105

104106
#define SKETCH_NAME "MySprinkler"
105-
#define SKETCH_VERSION "2.0"
107+
#define SKETCH_VERSION "2.2"
106108
//
107109
#define CHILD_ID_SPRINKLER 0
108110
//
@@ -149,6 +151,7 @@ bool buttonPushed = false;
149151
bool showTime = true;
150152
bool clockUpdating = false;
151153
bool recentUpdate = true;
154+
int allVars[] = {V_VAR1, V_VAR2, V_VAR3};
152155
const char *dayOfWeek[] = {
153156
"Null", "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "
154157
};
@@ -175,6 +178,7 @@ MyMessage var1valve(CHILD_ID_SPRINKLER, V_VAR1);
175178
MyMessage var2valve(CHILD_ID_SPRINKLER, V_VAR2);
176179

177180
bool receivedInitialValue = false;
181+
bool inSetup = true;
178182
//
179183
void setup()
180184
{
@@ -241,44 +245,11 @@ void setup()
241245
}
242246
}
243247
//
244-
lcd.clear();
245-
//Update valve data when first powered on
246-
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
248+
//Update valve data when first powered on
249+
for (byte i = 1; i <= NUMBER_OF_VALVES; i++)
247250
{
248-
lcd.print(F(" Updating "));
249-
lcd.setCursor(0, 1);
250-
lcd.print(F(" Valve Data: "));
251-
lcd.print(i);
252-
bool flashIcon = false;
253-
DEBUG_PRINT(F("Calling for Valve "));
254-
DEBUG_PRINT(i);
255-
DEBUG_PRINTLN(F(" Data..."));
256-
while (!receivedInitialValue)
257-
{
258-
lcd.setCursor(15, 0);
259-
flashIcon = !flashIcon;
260-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
261-
request(i, V_VAR1);
262-
wait(500);
263-
}
264-
receivedInitialValue = false;
265-
while (!receivedInitialValue)
266-
{
267-
lcd.setCursor(15, 0);
268-
flashIcon = !flashIcon;
269-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
270-
request(i, V_VAR2);
271-
wait(500);
272-
}
273-
receivedInitialValue = false;
274-
while (!receivedInitialValue)
275-
{
276-
lcd.setCursor(15, 0);
277-
flashIcon = !flashIcon;
278-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
279-
request(i, V_VAR3);
280-
wait(500);
281-
}
251+
lcd.clear();
252+
goGetValveTimes();
282253
}
283254
lcd.clear();
284255
}
@@ -359,6 +330,7 @@ void loop()
359330
{
360331
send(msg1valve.setSensor(i).set(false), false);
361332
}
333+
wait(50);
362334
}
363335
}
364336
lastValve = valveNumber;
@@ -394,6 +366,7 @@ void loop()
394366
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
395367
{
396368
send(msg1valve.setSensor(i).set(false), false);
369+
wait(50);
397370
}
398371
DEBUG_PRINT(F("State = "));
399372
DEBUG_PRINTLN(state);
@@ -416,6 +389,7 @@ void loop()
416389
{
417390
send(msg1valve.setSensor(i).set(false), false);
418391
}
392+
wait(50);
419393
}
420394
DEBUG_PRINTLN(F("State Changed, Single Zone Running..."));
421395
DEBUG_PRINT(F("Zone: "));
@@ -455,11 +429,14 @@ void loop()
455429
state = STAND_BY_ALL_OFF;
456430
}
457431
}
458-
else if (state == ZONE_SELECT_MENU)
432+
if (state == ZONE_SELECT_MENU)
459433
{
460434
displayMenu();
435+
}
436+
else
437+
{
438+
lastState = state;
461439
}
462-
lastState = state;
463440
}
464441
//
465442
void displayMenu(void)
@@ -624,9 +601,9 @@ void receive(const MyMessage &message)
624601
}
625602
valveNickName[i] = "";
626603
valveNickName[i] += newMessage;
627-
DEBUG_PRINT(F("Recieved new name for zone "));
604+
DEBUG_PRINT(F("Recieved variable3 valve: "));
628605
DEBUG_PRINT(i);
629-
DEBUG_PRINT(F(" and it is now called: "));
606+
DEBUG_PRINT(F(" = "));
630607
DEBUG_PRINTLN(valveNickName[i]);
631608
}
632609
receivedInitialValue = true;
@@ -645,7 +622,9 @@ void receive(const MyMessage &message)
645622
DEBUG_PRINT(F(" individual time: "));
646623
DEBUG_PRINT(valveSoloTime[i]);
647624
DEBUG_PRINT(F(" group time: "));
648-
DEBUG_PRINTLN(allZoneTime[i]);
625+
DEBUG_PRINT(allZoneTime[i]);
626+
DEBUG_PRINT(F(" name: "));
627+
DEBUG_PRINTLN(valveNickName[i]);
649628
recentUpdate = true;
650629
}
651630
}
@@ -868,17 +847,34 @@ void goGetValveTimes()
868847
{
869848
static unsigned long valveUpdateTime;
870849
static byte valveIndex = 1;
871-
if (millis() - valveUpdateTime >= 300000UL / NUMBER_OF_VALVES)// update each valve once every 5 mins (distributes the traffic)
850+
if (inSetup || millis() - valveUpdateTime >= VALVE_TIMES_RELOAD / NUMBER_OF_VALVES) // update each valve once every 5 mins (distributes the traffic)
872851
{
873-
DEBUG_PRINTLN(F("Calling for Valve Data..."));
874-
lcd.setCursor(15, 0);
875-
lcd.write(byte(1)); //lcd.write(1);
876-
request(valveIndex, V_VAR1);
877-
request(valveIndex, V_VAR2);
878-
request(valveIndex, V_VAR3);
852+
if (inSetup) {
853+
lcd.print(F(" Updating "));
854+
lcd.setCursor(0, 1);
855+
lcd.print(F(" Valve Data: "));
856+
lcd.print(valveIndex);
857+
}
858+
bool flashIcon = false;
859+
DEBUG_PRINT(F("Calling for Valve "));
860+
DEBUG_PRINT(valveIndex);
861+
DEBUG_PRINTLN(F(" Data..."));
862+
for (int a = 0; a < (sizeof(allVars)/sizeof(int)); a++) {
863+
receivedInitialValue = false;
864+
byte timeout = 10;
865+
while (!receivedInitialValue && timeout > 0)
866+
{
867+
lcd.setCursor(15, 0);
868+
flashIcon = !flashIcon;
869+
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
870+
request(valveIndex, allVars[a]);
871+
wait(50);
872+
timeout--;
873+
}
874+
}
879875
valveUpdateTime = millis();
880876
valveIndex++;
881-
if (valveIndex > NUMBER_OF_VALVES + 1)
877+
if (valveIndex > NUMBER_OF_VALVES)
882878
{
883879
valveIndex = 1;
884880
}

0 commit comments

Comments
 (0)