-
Notifications
You must be signed in to change notification settings - Fork 0
/
C_Web.ino
196 lines (155 loc) · 8.63 KB
/
C_Web.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/************************************************************************************************************************************************
* UpdateWeatherUnderground() : Routine to send weather data to Weather Underground, rapidfire *
* Returns true if WU accepted the data, false if anything went wrong *
************************************************************************************************************************************************
*/
/************************************************************************************************************************************************
************************************************************************************************************************************************
** Webpages **
************************************************************************************************************************************************
************************************************************************************************************************************************
*/
/************************************************************************************************************************************************
* Root *
* Just identify ourselves *
************************************************************************************************************************************************
*/
void handleRoot() {
server.send ( 200, "text/html", webPage );
}
/************************************************************************************************************************************************
* debug *
* Provide debug data *
************************************************************************************************************************************************
*/
void handleDebug() {
float DTime = 0;
float Level433 = 0;
int last_ntp;
String debugstr ="Weather Server Debug Page \r\nVersion: "; // system
debugstr += Version;
debugstr += "\r\n";
DTime = millis()/(10 * 60 * 60);
DTime = DTime/100; // do it this way to get 1/100th, otherwise comes as an integer
debugstr += String(DTime,2);
debugstr += " hours uptime\r\n\nLocal Time: ";
debugstr += String(NTP.getTimeDateString());
debugstr += "\r\nLast NTP Sync: "; // Radio levels
last_ntp = NTP.getLastNTPSync();
debugstr += String(NTP.getTimeDateString(last_ntp));
debugstr += "\r\n\nWiFi signal level = "; // Radio levels
debugstr += String(WiFi.RSSI());
debugstr += " dBm, 433MHz receiver signal level = "; // Crude approximation from the MICRF211 data sheet
Level433 = (((analogRead(A0) - 74)*80)/641) - 120; // note that the AD is apparently 0 to 3.2 Volt input range (default)
Level433 = constrain(Level433, -120, -40); // 0V = 0, 3.2V = 1024
debugstr += String(Level433,0);
debugstr += " dBm\r\n";
CurrentPressure = bme.readPressure() * 0.000295333727; // get the air pressure
debugstr += "\r\n\nAir Pressure = ";
debugstr += String(CurrentPressure,2); // Air pressure
debugstr += " inHg, ";
debugstr += String(bme.seaLevelForAltitude(204, bme.readPressure() / 100.0F));
debugstr += " hPa; Receiver Temperature = ";
debugstr += String(bme.readTemperature());
debugstr += " C, ";
debugstr += String(bme.readTemperature() * 1.8 + 32);
debugstr += " F, Air Humidity = ";
debugstr += String(bme.readHumidity(),2); // Humidity
debugstr += " % ";
debugstr += " \r\n\n5-in-1 Sensor:\r\nETA of next message: "; // 5-in-1
DTime = (Next5N1 + 18500 - millis())/1000;
debugstr += String(DTime,0);
debugstr += " seconds, Last good message was ";
DTime = (millis()-LastGood5N1)/1000;
debugstr += String(DTime,0);
debugstr += " seconds ago, Signal quality = ";
debugstr += String(Signal5N1,DEC);
debugstr += " out of 10\r\nTemperature = ";
debugstr += String(Temperature5N1,1);
debugstr += " C, Relative Humidity = ";
debugstr += String(Humidity5N1,DEC);
debugstr += "%\r\nDaily Rain = ";
debugstr += String(CurrentRain * 25.4,2);
debugstr += " mm, Current Rain Rate = ";
debugstr += String(RainRate * 25.4,2);
debugstr += " mm/hour, Rain Counter = ";
debugstr += String(RainCounter5N1,HEX);
debugstr += "\r\nWind = ";
debugstr += String(CurrentWind,1);
debugstr += " km/h, Direction = ";
debugstr += acurite_5n1_winddirection_str[CurrentDirection];
debugstr += ", Average = ";
debugstr += String(WindSpeedAverage,1);
debugstr += " km/h, Peak = ";
debugstr += String(WindSpeedPeak,1);
debugstr += " km/h at ";
debugstr += acurite_5n1_winddirection_str[WindPeakDirection];
if (BatteryLow5N1 == true) {
debugstr += " Direction\r\nBattery Low\r\n\n";
} else {
debugstr += " Direction\r\n\n";
}
debugstr += "\r\n\nReading#, 5N1 Signal, Rain, Wind Speed, Direction\r\n";
for ( int i = 32; i > 0; i-- ) { // signal, wind, and rain array
debugstr += String(i,DEC);
if (i < 10) {
debugstr += " ";
}
if (Mess5N1[i] == true) {
debugstr += " Good ";
} else {
debugstr += " Missed ";
}
// if (i < 11) { // only have ten message flags for tower sensor
// if (MessTower[i] == true) {
// debugstr += "Good ";
// } else {
// debugstr += "Missed ";
// }
// } else {
// debugstr += " ";
// }
debugstr += String(Rain[i] * 25.4,2);
debugstr += " ";
debugstr += String(WindSpeed[i],2);
debugstr += " ";
debugstr += acurite_5n1_winddirection_str[WindDirection[i]];
debugstr += "\r\n";
}
debugstr += "\r\n";
server.send ( 200, "text/plain", debugstr );
}
/************************************************************************************************************************************************
* RESET *
* Reset daily rainfall, assume it is midnight *
************************************************************************************************************************************************
*/
void handleSummerTime() {
server.send(200, "text/html", webPage);
Serial.println("[ON]");
if(NTP.getDayLight () == false) {
NTP.setDayLight(true);
}
}
void handleWinterTime() {
server.send(200, "text/html", webPage);
Serial.println("[OFF]");
if(NTP.getDayLight () == true) {
NTP.setDayLight(false);
}
}
void handleReset() {
String Wdata ="";
Wdata = " Today's total rain was ";
Wdata += String(CurrentRain * 25.4,2);
Wdata += " mm.";
UpdateRainCounter(); // reset daily rain fall
server.send ( 200, "text/plain", Wdata ); // today's (yesterday's really) total rain fall
}
/************************************************************************************************************************************************
* Requested page doesn't exist *
************************************************************************************************************************************************
*/
void handleNotFound() {
server.send ( 404, "text/plain", "Page Not Found" );
}