-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcisternMonitor.ino
67 lines (54 loc) · 1.17 KB
/
cisternMonitor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "user_specified.h"
// this is called when the 'thing' boots
void setup()
{
Serial.begin(9600); // debug data sent over serial port
initEEPROM();
initGPIO(); // Setup input/output I/O pins
if(timeToTakeReading())
{
Serial.println("time to take a reading");
connectWiFi();
incrementSleepCounter();
}
else
{
blinkLED(1,100);
// not time to take a reading yet, go back to sleep
incrementSleepCounter();
goToSleep();
}
}
// this is called continuously while the 'thing' is running
void loop()
{
if(WiFiConnected())
{
Serial.println("WiFi connected");
Serial.println("IP address: ");
showWiFiIP();
int waterLevel = getCisternLevel();
Serial.println("read water level: " + String(waterLevel));
if(waterLevel < 0)
{
blinkLED(1,2000);
blinkLED(-waterLevel,500);
}
else
{
blinkLED(waterLevel,500);
}
if(postToThingspeak(waterLevel) < 0)
{
// error posting data...try again next time we wake up
setSleepCounterToMax();
}
goToSleep();
}
else
{
Serial.println("[loop] no wifi");
blinkLED(1,100);
delay(500);
}
}