... | ... |
@@ -1,43 +1,43 @@ |
1 |
-#ifndef _MY_CONSTANTS |
|
2 |
-#define _MY_CONSTANTS |
|
3 |
- |
|
4 |
-#define APPVER "1.0.5" |
|
5 |
-#define APPNAME "DHT" |
|
6 |
-const char compile_date[] = APPNAME " v" APPVER " " __DATE__ " " __TIME__; |
|
7 |
-const char compile_time[] = __DATE__ " " __TIME__; |
|
8 |
- |
|
9 |
-//Global Switches |
|
10 |
-#define HAS_DHT |
|
11 |
-#define USE_MQTT |
|
12 |
-#define USE_OTA |
|
13 |
- |
|
14 |
-#define LED_BUILTIN 2 |
|
15 |
- |
|
16 |
-/* |
|
17 |
-#define MAX_RUNNING_TIME 50000 //50s |
|
18 |
-#define MAX_RUNNING_TIME 100000 //100s |
|
19 |
-#define MAX_RUNNING_TIME 3600000 //1hour |
|
20 |
-#define MAX_RUNNING_TIME 7200000 //2hours |
|
21 |
-#define MAX_RUNNING_TIME 10800000 //3hours |
|
22 |
-#define MAX_RUNNING_TIME 14400000 //4 hours |
|
23 |
-#define MAX_RUNNING_TIME 18000000 //5 hours |
|
24 |
-#define MAX_RUNNING_TIME 21600000 //6 hours |
|
25 |
-#define MAX_RUNNING_TIME 25200000 //7 hours |
|
26 |
-#define MAX_RUNNING_TIME 28800000 //8 hours |
|
27 |
-#define MAX_RUNNING_TIME 32400000 //9 hours |
|
28 |
-#define MAX_RUNNING_TIME 36000000 //10 hours |
|
29 |
-#define MAX_RUNNING_TIME 39600000 //11 hours |
|
30 |
-#define MAX_RUNNING_TIME 43200000 //12 hours |
|
31 |
-*/ |
|
32 |
-#define MAX_RUNNING_TIME 14400000 //4 hours |
|
33 |
-#define BLINK_FLASH // Define if you want flash blinking during Wifi connection attempts |
|
34 |
-//#define UPDATE_PERIOD 30000 // Will cause MQTT reconnect as it is too long |
|
35 |
-#define UPDATE_PERIOD 20000 |
|
36 |
-long timeSinceLastModeSwitch = 0; |
|
37 |
-uint32_t countMeasures=0; |
|
38 |
- |
|
39 |
- |
|
40 |
-//#define LOOP_DELAY 10 //Initial Value |
|
41 |
-#define LOOP_DELAY 100 //Test Value |
|
42 |
- |
|
43 |
-#endif //_MY_CONSTANTS |
|
1 |
+#ifndef _MY_CONSTANTS |
|
2 |
+#define _MY_CONSTANTS |
|
3 |
+ |
|
4 |
+#define APPVER "1.0.6" |
|
5 |
+#define APPNAME "DHT" |
|
6 |
+const char compile_date[] = APPNAME " v" APPVER " " __DATE__ " " __TIME__; |
|
7 |
+const char compile_time[] = __DATE__ " " __TIME__; |
|
8 |
+ |
|
9 |
+//Global Switches |
|
10 |
+#define HAS_DHT |
|
11 |
+#define USE_MQTT |
|
12 |
+#define USE_OTA |
|
13 |
+ |
|
14 |
+#define LED_BUILTIN 2 |
|
15 |
+ |
|
16 |
+/* |
|
17 |
+#define MAX_RUNNING_TIME 50000 //50s |
|
18 |
+#define MAX_RUNNING_TIME 100000 //100s |
|
19 |
+#define MAX_RUNNING_TIME 3600000 //1hour |
|
20 |
+#define MAX_RUNNING_TIME 7200000 //2hours |
|
21 |
+#define MAX_RUNNING_TIME 10800000 //3hours |
|
22 |
+#define MAX_RUNNING_TIME 14400000 //4 hours |
|
23 |
+#define MAX_RUNNING_TIME 18000000 //5 hours |
|
24 |
+#define MAX_RUNNING_TIME 21600000 //6 hours |
|
25 |
+#define MAX_RUNNING_TIME 25200000 //7 hours |
|
26 |
+#define MAX_RUNNING_TIME 28800000 //8 hours |
|
27 |
+#define MAX_RUNNING_TIME 32400000 //9 hours |
|
28 |
+#define MAX_RUNNING_TIME 36000000 //10 hours |
|
29 |
+#define MAX_RUNNING_TIME 39600000 //11 hours |
|
30 |
+#define MAX_RUNNING_TIME 43200000 //12 hours |
|
31 |
+*/ |
|
32 |
+#define MAX_RUNNING_TIME 14400000 //4 hours |
|
33 |
+#define BLINK_FLASH // Define if you want flash blinking during Wifi connection attempts |
|
34 |
+//#define UPDATE_PERIOD 30000 // Will cause MQTT reconnect as it is too long |
|
35 |
+#define UPDATE_PERIOD 20000 |
|
36 |
+long timeSinceLastModeSwitch = 0; |
|
37 |
+uint32_t countMeasures=0; |
|
38 |
+ |
|
39 |
+ |
|
40 |
+//#define LOOP_DELAY 10 //Initial Value |
|
41 |
+#define LOOP_DELAY 100 //Test Value |
|
42 |
+ |
|
43 |
+#endif //_MY_CONSTANTS |
... | ... |
@@ -1,111 +1,152 @@ |
1 |
-#ifndef _MY_HTTP |
|
2 |
-#define _MY_HTTP |
|
3 |
-#include <ESP8266WebServer.h> |
|
4 |
- |
|
5 |
-#ifdef USE_OTA |
|
6 |
-#include "my_ota.h" |
|
7 |
-#include <ESP8266HTTPUpdateServer.h> |
|
8 |
- |
|
9 |
-#define OTAUSER "admin" // Set OTA user |
|
10 |
-#define OTAPASSWORD "admin" // Set OTA password |
|
11 |
-#define OTAPATH "/ota"// Set path for update |
|
12 |
-ESP8266HTTPUpdateServer httpUpdater; |
|
13 |
-#endif //USE_OTA |
|
14 |
- |
|
15 |
-#define PORT 80 |
|
16 |
-ESP8266WebServer server(PORT); |
|
17 |
- |
|
18 |
- |
|
19 |
-String message=""; |
|
20 |
- |
|
21 |
-void handleRoot() { |
|
22 |
- unsigned long time = millis()/1000; |
|
23 |
- byte mac[6]; |
|
24 |
- char macStr[6]; |
|
25 |
- WiFi.macAddress(mac); |
|
26 |
- sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]); |
|
27 |
- String macStrString=macStr; |
|
28 |
- message = ""; |
|
29 |
- message += "<!DOCTYPE HTML><html>"; |
|
30 |
- message += "<head>"; |
|
31 |
- message += " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; |
|
32 |
- message += " <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.7.2/css/all.css\" integrity=\"sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr\" crossorigin=\"anonymous\">"; |
|
33 |
- message += " <title>esp8266-"+macStrString+"</title>"; |
|
34 |
- message += "<style>"; |
|
35 |
- message += "html{font-family:Arial;display:inline-block;margin:0px auto;text-align:center;}"; |
|
36 |
- message += "h2{font-size:2.0rem;}"; |
|
37 |
- message += "p{font-size:3.0rem;}"; |
|
38 |
- message += ".app {font-size:0.8rem;font-style: italic;}"; |
|
39 |
- message += ".dht-labels{font-size:1.5rem;vertical-align:middle;padding-bottom:15px;}"; |
|
40 |
- message += "</style>"; |
|
41 |
- message += "</head>"; |
|
42 |
- message += "<body>"; |
|
43 |
- message += "<h2>esp8266-"+macStrString+"</h2>"; |
|
44 |
- message += "<p><i class=\"fas fa-thermometer-half\" style=\"color:#059e8a;\"></i><span class=\"dht-labels\">Temperature</span> <span id=\"temperature\">"+String(readDHTTemperature())+"</span><sup class=\"units\">°C</sup></p>"; |
|
45 |
- message += "<p><i class=\"fas fa-tint\" style=\"color:#00add6;\"></i><span class=\"dht-labels\">Humidity</span> <span id=\"temperature\">"+String(readDHTHumidity())+"</span><sup class=\"units\">%</sup></p>"; |
|
46 |
- message += "<p><i class=\"fas fa-clock\" style=\"color:#00add6;\"></i><span class=\"dht-labels\">Date</span> <span id=\"temperature\">"+String(acTimeString)+"</span></p>"; |
|
47 |
- message += "<div class=\"app\">"+String(compile_date)+"</div>"; |
|
48 |
- message += "</body></html>"; |
|
49 |
- server.send(200, "text/html", message ); |
|
50 |
-} |
|
51 |
-void handleT() { |
|
52 |
- server.send(200, "text/html", String(readDHTTemperature()) ); |
|
53 |
-} |
|
54 |
-void handleH() { |
|
55 |
- server.send(200, "text/html", String(readDHTHumidity()) ); |
|
56 |
-} |
|
57 |
-void handleS() { |
|
58 |
- byte mac[6]; |
|
59 |
- char macStr[6]; |
|
60 |
- WiFi.macAddress(mac); |
|
61 |
- //float vccVolt = ((float)ESP.getVcc())/1024; |
|
62 |
- float vccVolt = (float)ESP.getVcc(); |
|
63 |
- sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]); |
|
64 |
- String statusMsg = "{"; |
|
65 |
- statusMsg += "\"app_name\": \""+String(APPNAME)+"\","; |
|
66 |
- statusMsg += "\"app_version\": \""+String(APPVER)+"\","; |
|
67 |
- statusMsg += "\"build_date\": \""+String(compile_time)+"\","; |
|
68 |
- statusMsg += "\"mac\": \""+WiFi.macAddress()+"\","; |
|
69 |
- statusMsg += "\"ip\": \""+WiFiIP+"\","; |
|
70 |
- statusMsg += "\"ota_name\": \"esp8266-"+String(macStr)+"\","; |
|
71 |
- statusMsg += "\"uptime\": "+String(millis())+","; |
|
72 |
- statusMsg += "\"countMeasures\": "+String(countMeasures)+","; |
|
73 |
- statusMsg += "\"period\": "+String(UPDATE_PERIOD)+","; |
|
74 |
- statusMsg += "\"loop_delay\": "+String(LOOP_DELAY)+","; |
|
75 |
- statusMsg += "\"vcc\": "+String(vccVolt)+","; |
|
76 |
- statusMsg += "\"last_update\": \""+String(acTimeStringTZ)+"\""; |
|
77 |
- statusMsg += "}"; |
|
78 |
- server.send(200, "text/html", String(statusMsg) ); |
|
79 |
-} |
|
80 |
- |
|
81 |
-void handleNotFound() { |
|
82 |
- String message = "File Not Found\n\n"; |
|
83 |
- message += "URI: "; |
|
84 |
- message += server.uri(); |
|
85 |
- message += "\nMethod: "; |
|
86 |
- message += (server.method() == HTTP_GET) ? "GET" : "POST"; |
|
87 |
- message += "\nArguments: "; |
|
88 |
- message += server.args(); |
|
89 |
- message += "\n"; |
|
90 |
- |
|
91 |
- for (uint8_t i = 0; i < server.args(); i++) { |
|
92 |
- message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; |
|
93 |
- } |
|
94 |
- server.send(404, "text/plain", message); |
|
95 |
-} |
|
96 |
- |
|
97 |
- |
|
98 |
-void http_set() { |
|
99 |
- server.on("/", handleRoot); |
|
100 |
- server.on("/temperature", handleT); |
|
101 |
- server.on("/humidity", handleH); |
|
102 |
- server.on("/status", handleS); |
|
103 |
- server.onNotFound(handleNotFound); |
|
104 |
- server.begin(); |
|
105 |
- |
|
106 |
-#ifdef USE_OTA |
|
107 |
- //httpUpdater.setup(&server, OTAPATH, OTAUSER, OTAPASSWORD); |
|
108 |
- httpUpdater.setup(&server, OTAPATH, OTAUSER, WiFi.macAddress().c_str()); |
|
109 |
-#endif //USE_OTA |
|
110 |
-} |
|
111 |
-#endif //_MY_HTTP |
|
1 |
+#ifndef _MY_HTTP |
|
2 |
+#define _MY_HTTP |
|
3 |
+#include <ESP8266WebServer.h> |
|
4 |
+ |
|
5 |
+#ifdef USE_OTA |
|
6 |
+#include "my_ota.h" |
|
7 |
+#include <ESP8266HTTPUpdateServer.h> |
|
8 |
+ |
|
9 |
+#define OTAUSER "admin" // Set OTA user |
|
10 |
+#define OTAPASSWORD "admin" // Set OTA password |
|
11 |
+#define OTAPATH "/ota"// Set path for update |
|
12 |
+ESP8266HTTPUpdateServer httpUpdater; |
|
13 |
+#endif //USE_OTA |
|
14 |
+ |
|
15 |
+#define PORT 80 |
|
16 |
+ESP8266WebServer server(PORT); |
|
17 |
+ |
|
18 |
+ |
|
19 |
+String message=""; |
|
20 |
+ |
|
21 |
+void handleRoot() { |
|
22 |
+ unsigned long time = millis()/1000; |
|
23 |
+ byte mac[6]; |
|
24 |
+ char macStr[6]; |
|
25 |
+ WiFi.macAddress(mac); |
|
26 |
+ sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]); |
|
27 |
+ String macStrString=macStr; |
|
28 |
+ message = ""; |
|
29 |
+ message += "<!DOCTYPE HTML><html>"; |
|
30 |
+ message += "<head>"; |
|
31 |
+ message += " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; |
|
32 |
+ message += " <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.7.2/css/all.css\" integrity=\"sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr\" crossorigin=\"anonymous\">"; |
|
33 |
+ message += " <title>esp8266-"+macStrString+"</title>"; |
|
34 |
+ message += "<style>"; |
|
35 |
+ message += "html{font-family:Arial;display:inline-block;margin:0px auto;text-align:center;}"; |
|
36 |
+ message += "h2{font-size:2.0rem;}"; |
|
37 |
+ message += "p{font-size:3.0rem;}"; |
|
38 |
+ message += "ul {list-style-type: none; margin: 0; padding: 0;text-align: left;}"; |
|
39 |
+ message += "li {list-style-type: none; margin: 0; padding: 0;text-align: left;}"; |
|
40 |
+ message += ".app {font-size:0.8rem;font-style: italic;}"; |
|
41 |
+ message += ".dht-labels{font-size:1.5rem;vertical-align:middle;padding-bottom:15px;}"; |
|
42 |
+ message += "</style>"; |
|
43 |
+ message += "</head>"; |
|
44 |
+ message += "<body>"; |
|
45 |
+ message += "<h2>esp8266-"+macStrString+"</h2>"; |
|
46 |
+ message += "<p><i class=\"fas fa-thermometer-half\" style=\"color:#059e8a;\"></i><span class=\"dht-labels\">Temperature</span> <span id=\"temperature\">"+String(readDHTTemperature())+"</span><sup class=\"units\">°C</sup></p>"; |
|
47 |
+ message += "<p><i class=\"fas fa-tint\" style=\"color:#00add6;\"></i><span class=\"dht-labels\">Humidity</span> <span id=\"temperature\">"+String(readDHTHumidity())+"</span><sup class=\"units\">%</sup></p>"; |
|
48 |
+ message += "<p><i class=\"fas fa-clock\" style=\"color:#00add6;\"></i><span class=\"dht-labels\">Date</span> <span id=\"temperature\">"+String(acTimeString)+"</span></p>"; |
|
49 |
+ message += "<div class=\"app\">"+String(compile_date)+"</div>"; |
|
50 |
+ message += "<ul class=\"links\">"; |
|
51 |
+ message += "<li><a href=\"/status\">/status</li>"; |
|
52 |
+ message += "<li><a href=\"/ota\">/ota</li>"; |
|
53 |
+ message += "<li><a href=\"/json\">/json</li>"; |
|
54 |
+ message += "<li><a href=\"/csv\">/csv</li>"; |
|
55 |
+ message += "</ul>"; |
|
56 |
+ message += "</body></html>"; |
|
57 |
+ server.send(200, "text/html", message ); |
|
58 |
+} |
|
59 |
+void handleT() { |
|
60 |
+ server.send(200, "text/html", String(readDHTTemperature()) ); |
|
61 |
+} |
|
62 |
+void handleH() { |
|
63 |
+ server.send(200, "text/html", String(readDHTHumidity()) ); |
|
64 |
+} |
|
65 |
+void handleJSON() { |
|
66 |
+ byte mac[6]; |
|
67 |
+ char macStr[6]; |
|
68 |
+ WiFi.macAddress(mac); |
|
69 |
+ float vccVolt = (float)ESP.getVcc(); |
|
70 |
+ sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]); |
|
71 |
+ String statusMsg = "{"; |
|
72 |
+ statusMsg += "\"ota_name\": \"esp8266-"+String(macStr)+"\","; |
|
73 |
+ statusMsg += "\"uptime\": "+String(millis())+","; |
|
74 |
+ statusMsg += "\"countMeasures\": "+String(countMeasures)+","; |
|
75 |
+ statusMsg += "\"vcc\": "+String(vccVolt)+","; |
|
76 |
+ statusMsg += "\"temperature\": "+String(readDHTTemperature())+","; |
|
77 |
+ statusMsg += "\"humidity\": "+String(readDHTHumidity())+","; |
|
78 |
+ statusMsg += "\"last_update\": \""+String(acTimeStringTZ)+"\""; |
|
79 |
+ statusMsg += "}"; |
|
80 |
+ server.send(200, "text/html", String(statusMsg) ); |
|
81 |
+} |
|
82 |
+void handleCSV() { |
|
83 |
+ byte mac[6]; |
|
84 |
+ char macStr[6]; |
|
85 |
+ WiFi.macAddress(mac); |
|
86 |
+ float vccVolt = (float)ESP.getVcc(); |
|
87 |
+ sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]); |
|
88 |
+ String statusMsg = "esp8266-"+String(macStr)+","; |
|
89 |
+ statusMsg += String(millis())+","; |
|
90 |
+ statusMsg += String(countMeasures)+","; |
|
91 |
+ statusMsg += String(vccVolt)+","; |
|
92 |
+ statusMsg += String(readDHTTemperature())+","; |
|
93 |
+ statusMsg += String(readDHTHumidity())+","; |
|
94 |
+ statusMsg += String(acTimeStringTZ)+","; |
|
95 |
+ server.send(200, "text/html", String(statusMsg) ); |
|
96 |
+} |
|
97 |
+void handleSTATUS() { |
|
98 |
+ byte mac[6]; |
|
99 |
+ char macStr[6]; |
|
100 |
+ WiFi.macAddress(mac); |
|
101 |
+ float vccVolt = (float)ESP.getVcc(); |
|
102 |
+ sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]); |
|
103 |
+ String statusMsg = "{"; |
|
104 |
+ statusMsg += "\"app_name\": \""+String(APPNAME)+"\","; |
|
105 |
+ statusMsg += "\"app_version\": \""+String(APPVER)+"\","; |
|
106 |
+ statusMsg += "\"build_date\": \""+String(compile_time)+"\","; |
|
107 |
+ statusMsg += "\"mac\": \""+WiFi.macAddress()+"\","; |
|
108 |
+ statusMsg += "\"ip\": \""+WiFiIP+"\","; |
|
109 |
+ statusMsg += "\"ota_name\": \"esp8266-"+String(macStr)+"\","; |
|
110 |
+ statusMsg += "\"uptime\": "+String(millis())+","; |
|
111 |
+ statusMsg += "\"countMeasures\": "+String(countMeasures)+","; |
|
112 |
+ statusMsg += "\"period\": "+String(UPDATE_PERIOD)+","; |
|
113 |
+ statusMsg += "\"loop_delay\": "+String(LOOP_DELAY)+","; |
|
114 |
+ statusMsg += "\"vcc\": "+String(vccVolt)+","; |
|
115 |
+ statusMsg += "\"last_update\": \""+String(acTimeStringTZ)+"\""; |
|
116 |
+ statusMsg += "}"; |
|
117 |
+ server.send(200, "text/html", String(statusMsg) ); |
|
118 |
+} |
|
119 |
+ |
|
120 |
+void handleNotFound() { |
|
121 |
+ String message = "File Not Found\n\n"; |
|
122 |
+ message += "URI: "; |
|
123 |
+ message += server.uri(); |
|
124 |
+ message += "\nMethod: "; |
|
125 |
+ message += (server.method() == HTTP_GET) ? "GET" : "POST"; |
|
126 |
+ message += "\nArguments: "; |
|
127 |
+ message += server.args(); |
|
128 |
+ message += "\n"; |
|
129 |
+ |
|
130 |
+ for (uint8_t i = 0; i < server.args(); i++) { |
|
131 |
+ message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; |
|
132 |
+ } |
|
133 |
+ server.send(404, "text/plain", message); |
|
134 |
+} |
|
135 |
+ |
|
136 |
+ |
|
137 |
+void http_set() { |
|
138 |
+ server.on("/", handleRoot); |
|
139 |
+ server.on("/temperature", handleT); |
|
140 |
+ server.on("/humidity", handleH); |
|
141 |
+ server.on("/status", handleSTATUS); |
|
142 |
+ server.on("/json", handleJSON); |
|
143 |
+ server.on("/csv", handleCSV); |
|
144 |
+ server.onNotFound(handleNotFound); |
|
145 |
+ server.begin(); |
|
146 |
+ |
|
147 |
+#ifdef USE_OTA |
|
148 |
+ //httpUpdater.setup(&server, OTAPATH, OTAUSER, OTAPASSWORD); |
|
149 |
+ httpUpdater.setup(&server, OTAPATH, OTAUSER, WiFi.macAddress().c_str()); |
|
150 |
+#endif //USE_OTA |
|
151 |
+} |
|
152 |
+#endif //_MY_HTTP |