-
Notifications
You must be signed in to change notification settings - Fork 0
/
fieldsensor-v5.ino
97 lines (73 loc) · 2.53 KB
/
fieldsensor-v5.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//FILE: fieldsensor-v4.ino
#include "field.h"
STARTUP(System.enableFeature(FEATURE_RESET_INFO)); // Enabling reason for last reset to check for crashes
STARTUP(WiFi.selectAntenna(ANT_AUTO)); // Auto search for antenna
int signalstrength;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(errorPin, OUTPUT);
pinMode(solarPin, INPUT);
digitalWrite(relayPin, HIGH);
// Next lines for power shield
batteryMonitor.begin();
// This sets up the fuel gauge
batteryMonitor.quickStart();
if (System.resetReason() == 0) {
Particle.publish("ERROR", "CRASH, ENTERING SAFE MODE");
System.enterSafeMode();
}
// Config Set up
myconfig.setup();
// Checking if connected to the internet
if(Particle.connected() == false){
digitalWrite(errorPin, HIGH);
myconfig.errorMsg("Particle Cloud");
}
myconfig.oledPrint(0,0, "ON", true, 2.75);
//Initializing the UV Sensor
while(! uv.begin()) {
myconfig.oledPrint(0,0,"error", true, 2.5);
delay(1000);
}
// Beginning the MicroSD card and checking for any error
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
myconfig.errorMsg("SD card Error");
sd.initErrorHalt();
}
sht20.initSHT20(); // Init SHT20 Sensor
delay(100);
sht20.checkSHT20(); // Check SHT20 Sensor
// Setting default address of soil moisture to 0x20
i2CSoilMoistureSensorDefault.begin();
}
void loop() {
// Syncing and setting time zone to pacific
Particle.syncTime();
Time.zone(tZone);
delay(1000);
getTemp();
getUV();
getMositure();
getPower();
//Converting float ints to char arrays and then strings
sprintf(chTemp, "%2.2f", fTempF);
sprintf(chUVInfo, "%2.2f", fUVIndex);
sprintf(chHumidity, "%2.2f", fHumidity);
sprintf(chIntTemp, "%2.2f", fIntTempF);
sprintf(chVisibleLight, "%2.2f", fVisibleLight);
sprintf(chSoilMositure, "%2.2f", fSoilMositure);
sprintf(chSolarVolt, "%2.2f", fSolarVolt);
sprintf(chBatPercent, "%2.2f", fStateOfCharge);
oled();
delay(1000);
currentMemory = System.freeMemory();
//Particle.publish("mem", currentMemory);
publishData(); // Published and logs to the SD card
signalstrength = WiFi.RSSI();
Particle.publish("Signal", String(signalstrength));
delay(bufferTime);
display.clearDisplay();
display.display();
digitalWrite(relayPin, LOW);
System.sleep(SLEEP_MODE_DEEP, INTERVAL_TIME);
}