Showing 6 changed files with 296 additions and 278 deletions
+9 -9
DHT.ino
... ...
@@ -24,14 +24,8 @@
24 24
 #include "my_ntp.h"
25 25
 #include "my_isr.h"
26 26
 
27
-#ifdef USE_OTA
28 27
 #include "my_ota.h"
29
-#endif //USE_OTA
30
-
31
-#ifdef USE_MQTT
32 28
 #include "my_mqtt.h"
33
-#endif //USE_MQTT
34
-
35 29
 #include "my_http.h"
36 30
 
37 31
 ADC_MODE(ADC_VCC);
... ...
@@ -54,8 +48,8 @@ void setup() {
54 48
   // Sync clock
55 49
   if( WiFi.status() == WL_CONNECTED ) {
56 50
     setClock();
57
-    sprintf(clientID,clientIDFmt,WiFi.macAddress().c_str());
58 51
 #ifdef USE_MQTT
52
+    sprintf(clientID,clientIDFmt,WiFi.macAddress().c_str());
59 53
     mqtt_connect();
60 54
 #endif //USE_MQTT
61 55
   }
... ...
@@ -77,7 +71,10 @@ void setup() {
77 71
 
78 72
 // the loop function runs over and over again forever
79 73
 void loop() {
74
+  #ifdef USE_OTA
75
+  //HttpOtaServer.handleClient();
80 76
   ArduinoOTA.handle();
77
+  #endif //USE_OTA
81 78
   unsigned long time;
82 79
   time = millis();
83 80
   if (time - timeSinceLastModeSwitch > UPDATE_PERIOD) {
... ...
@@ -101,19 +98,22 @@ void loop() {
101 98
   } else if( time > MAX_RUNNING_TIME ) {
102 99
       //Restart the board if running time is > MAX_RUNNING_TIME
103 100
       #ifdef USE_MQTT
101
+      //WiFi.forceSleepWake();
104 102
       mqtt_reconnect();
105 103
       String MQTTMsg = "{\"time\": \""+String(acTimeStringTZ)+"\", \"MAC\": \""+WiFi.macAddress()+"\", \"status\": \"Triggered reboot\"}";
106 104
       if (!client.publish(mqtt_topic, MQTTMsg.c_str())) {
107 105
         Serial.println("ERROR: MQTT not sent!");
108 106
       }
109
-      #endif //USE_MQTT  
107
+      #endif //USE_MQTT
110 108
       Serial.println("Triggered reboot");
111 109
       ESP.restart();
112 110
     } else if(WiFi.status() != WL_CONNECTED) {
113 111
       //Reconnect WiFi if not connected
114 112
       WiFiConnect();
113
+      #ifdef USE_MQTT
115 114
       mqtt_connect();
115
+      #endif //USE_MQTT
116 116
     }
117
-  server.handleClient();  
117
+  server.handleClient();
118 118
   delay(LOOP_DELAY);
119 119
 }
+43 -43
my_constants.h
... ...
@@ -1,43 +1,43 @@
1
-#ifndef _MY_CONSTANTS
2
-#define _MY_CONSTANTS
3
-
4
-#define APPVER  "1.0.4"
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.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
+111 -100
my_http.h
... ...
@@ -1,100 +1,111 @@
1
-#ifndef _MY_HTTP
2
-#define _MY_HTTP
3
-#include <ESP8266WebServer.h>
4
-
5
-#ifdef USE_OTA
6
-#include "my_ota.h"
7
-#endif //USE_OTA
8
-
9
-#define PORT 80
10
-ESP8266WebServer server(PORT);
11
-
12
-
13
-String message="";
14
-
15
-void handleRoot() {
16
-  unsigned long time = millis()/1000;
17
-  byte mac[6];
18
-  char macStr[6];
19
-  WiFi.macAddress(mac);
20
-  sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]);
21
-  String macStrString=macStr;
22
-  message = "";
23
-  message += "<!DOCTYPE HTML><html>";
24
-  message += "<head>";
25
-  message += "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
26
-  message += "  <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.7.2/css/all.css\" integrity=\"sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr\" crossorigin=\"anonymous\">";
27
-  message += "  <title>esp8266-"+macStrString+"</title>";
28
-  message += "<style>";
29
-  message += "html{font-family:Arial;display:inline-block;margin:0px auto;text-align:center;}";
30
-  message += "h2{font-size:2.0rem;}";
31
-  message += "p{font-size:3.0rem;}";
32
-  message += ".app {font-size:0.8rem;font-style: italic;}";
33
-  message += ".dht-labels{font-size:1.5rem;vertical-align:middle;padding-bottom:15px;}";
34
-  message += "</style>";
35
-  message += "</head>";
36
-  message += "<body>";
37
-  message += "<h2>esp8266-"+macStrString+"</h2>";
38
-  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\">&deg;C</sup></p>";
39
-  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>";
40
-  message += "<p><i class=\"fas fa-clock\" style=\"color:#00add6;\"></i><span class=\"dht-labels\">Date</span> <span id=\"temperature\">"+String(acTimeString)+"</span></p>";
41
-  message += "<div class=\"app\">"+String(compile_date)+"</div>";
42
-  message += "</body></html>";
43
-  server.send(200, "text/html", message );
44
-}
45
-void handleT() {
46
-  server.send(200, "text/html", String(readDHTTemperature()) );
47
-}
48
-void handleH() {
49
-  server.send(200, "text/html", String(readDHTHumidity()) );
50
-}
51
-void handleS() {
52
-  byte mac[6];
53
-  char macStr[6];
54
-  WiFi.macAddress(mac);
55
-  //float vccVolt = ((float)ESP.getVcc())/1024;
56
-  float vccVolt = (float)ESP.getVcc();
57
-  sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]);
58
-  String statusMsg = "{";
59
-  statusMsg += "\"app_name\": \""+String(APPNAME)+"\",";
60
-  statusMsg += "\"app_version\": \""+String(APPVER)+"\",";
61
-  statusMsg += "\"build_date\": \""+String(compile_time)+"\",";
62
-  statusMsg += "\"mac\": \""+WiFi.macAddress()+"\",";
63
-  statusMsg += "\"ip\": \""+WiFiIP+"\",";
64
-  statusMsg += "\"ota_name\": \"esp8266-"+String(macStr)+"\",";
65
-  statusMsg += "\"uptime\": "+String(millis())+",";
66
-  statusMsg += "\"countMeasures\": "+String(countMeasures)+",";
67
-  statusMsg += "\"period\": "+String(UPDATE_PERIOD)+",";
68
-  statusMsg += "\"loop_delay\": "+String(LOOP_DELAY)+",";
69
-  statusMsg += "\"vcc\": "+String(vccVolt)+",";
70
-  statusMsg += "\"last_update\": \""+String(acTimeStringTZ)+"\"";
71
-  statusMsg += "}";
72
-  server.send(200, "text/html", String(statusMsg) );
73
-}
74
-
75
-void handleNotFound() {
76
-  String message = "File Not Found\n\n";
77
-  message += "URI: ";
78
-  message += server.uri();
79
-  message += "\nMethod: ";
80
-  message += (server.method() == HTTP_GET) ? "GET" : "POST";
81
-  message += "\nArguments: ";
82
-  message += server.args();
83
-  message += "\n";
84
-
85
-  for (uint8_t i = 0; i < server.args(); i++) {
86
-    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
87
-  }
88
-  server.send(404, "text/plain", message);
89
-}
90
-
91
-
92
-void http_set() {
93
-  server.on("/", handleRoot);
94
-  server.on("/temperature", handleT);
95
-  server.on("/humidity", handleH);
96
-  server.on("/status", handleS);
97
-  server.onNotFound(handleNotFound);
98
-  server.begin();
99
-}
100
-#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 += ".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\">&deg;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
+80 -78
my_isr.h
... ...
@@ -1,78 +1,80 @@
1
-#ifndef _MY_ISR_H
2
-#define _MY_ISR_H
3
-
4
-#include "my_mqtt.h"
5
-
6
-#ifdef ARDUINO_ESP8266_WEMOS_D1R1
7
-uint8_t buttonDown=0;
8
-uint8_t buttonUp=0;
9
-uint8_t buttonRight=0;
10
-uint8_t buttonPush=0;
11
-
12
-void ICACHE_RAM_ATTR interrupt0() // Right
13
-{
14
-  //Way: Opposite screen
15
-  // Disabled as it makes the board reboot
16
-  Serial.println("Right");
17
-  if(0==buttonRight) {
18
-    buttonRight = 1;
19
-    WiFiConnect();
20
-    mqtt_connect();
21
-  } else {
22
-    buttonRight = 0;
23
-  }
24
-}
25
-
26
-void ICACHE_RAM_ATTR interrupt12() // Down
27
-{
28
-  //Way: Toward edge of the board
29
-  Serial.println("Down");
30
-  if(0==buttonDown) {
31
-    buttonDown = 1;
32
-  } else {
33
-    buttonDown = 0;
34
-  }
35
-  displaySetStatus(buttonDown);
36
-}
37
-
38
-void ICACHE_RAM_ATTR interrupt13() // Up
39
-{
40
-  //Way: Toward hole in the board
41
-  Serial.println("Up");
42
-  if(0==buttonUp) {
43
-    buttonUp = 1;
44
-  } else {
45
-    buttonUp = 0;
46
-  }
47
-  displaySetStatus(1);
48
-  //WiFiConnect();
49
-  WiFi.disconnect(true);
50
-  //WiFi.mode(WIFI_STA);
51
-}
52
-
53
-void ICACHE_RAM_ATTR interrupt14() // Push
54
-{
55
-  //Way: Toward hole in the board
56
-  Serial.println("Push");
57
-  if(0==buttonPush) {
58
-    buttonPush = 1;
59
-  } else {
60
-    buttonPush = 0;
61
-  }
62
-}
63
-
64
-void isr_set() {
65
-  //pinMode(0, INPUT_PULLUP);
66
-  //attachInterrupt(digitalPinToInterrupt(0), interrupt0, FALLING);    // Right
67
-  pinMode(12, INPUT_PULLUP);
68
-  attachInterrupt(digitalPinToInterrupt(12), interrupt12, FALLING);  // Down
69
-  pinMode(13, INPUT_PULLUP);
70
-  attachInterrupt(digitalPinToInterrupt(13), interrupt13, FALLING);  // Up
71
-  pinMode(14, INPUT_PULLUP);
72
-  attachInterrupt(digitalPinToInterrupt(14), interrupt14, FALLING); // Push
73
-}
74
-#else
75
-void isr_set() {}
76
-#endif //ARDUINO_ESP8266_WEMOS_D1R1
77
-
78
-#endif //_MY_ISR_H
1
+#ifndef _MY_ISR_H
2
+#define _MY_ISR_H
3
+
4
+#include "my_mqtt.h"
5
+
6
+#ifdef ARDUINO_ESP8266_WEMOS_D1R1
7
+uint8_t buttonDown=0;
8
+uint8_t buttonUp=0;
9
+uint8_t buttonRight=0;
10
+uint8_t buttonPush=0;
11
+
12
+void ICACHE_RAM_ATTR interrupt0() // Right
13
+{
14
+  //Way: Opposite screen
15
+  // Disabled as it makes the board reboot
16
+  Serial.println("Right");
17
+  if(0==buttonRight) {
18
+    buttonRight = 1;
19
+    WiFiConnect();
20
+    #ifdef USE_MQTT
21
+    mqtt_connect();
22
+    #endif //USE_MQTT
23
+  } else {
24
+    buttonRight = 0;
25
+  }
26
+}
27
+
28
+void ICACHE_RAM_ATTR interrupt12() // Down
29
+{
30
+  //Way: Toward edge of the board
31
+  Serial.println("Down");
32
+  if(0==buttonDown) {
33
+    buttonDown = 1;
34
+  } else {
35
+    buttonDown = 0;
36
+  }
37
+  displaySetStatus(buttonDown);
38
+}
39
+
40
+void ICACHE_RAM_ATTR interrupt13() // Up
41
+{
42
+  //Way: Toward hole in the board
43
+  Serial.println("Up");
44
+  if(0==buttonUp) {
45
+    buttonUp = 1;
46
+  } else {
47
+    buttonUp = 0;
48
+  }
49
+  displaySetStatus(1);
50
+  //WiFiConnect();
51
+  WiFi.disconnect(true);
52
+  //WiFi.mode(WIFI_STA);
53
+}
54
+
55
+void ICACHE_RAM_ATTR interrupt14() // Push
56
+{
57
+  //Way: Toward hole in the board
58
+  Serial.println("Push");
59
+  if(0==buttonPush) {
60
+    buttonPush = 1;
61
+  } else {
62
+    buttonPush = 0;
63
+  }
64
+}
65
+
66
+void isr_set() {
67
+  //pinMode(0, INPUT_PULLUP);
68
+  //attachInterrupt(digitalPinToInterrupt(0), interrupt0, FALLING);    // Right
69
+  pinMode(12, INPUT_PULLUP);
70
+  attachInterrupt(digitalPinToInterrupt(12), interrupt12, FALLING);  // Down
71
+  pinMode(13, INPUT_PULLUP);
72
+  attachInterrupt(digitalPinToInterrupt(13), interrupt13, FALLING);  // Up
73
+  pinMode(14, INPUT_PULLUP);
74
+  attachInterrupt(digitalPinToInterrupt(14), interrupt14, FALLING); // Push
75
+}
76
+#else
77
+void isr_set() {}
78
+#endif //ARDUINO_ESP8266_WEMOS_D1R1
79
+
80
+#endif //_MY_ISR_H
+8 -5
my_mqtt.h
... ...
@@ -2,13 +2,13 @@
2 2
 #define _MQTT_H
3 3
 
4 4
 #include <PubSubClient.h> // Allows us to connect to, and publish to the MQTT broker
5
-
5
+#ifdef USE_MQTT
6 6
 
7 7
 // MQTT
8 8
 const int MAX_MQTT_CNX_RETRIES = 3;
9 9
 static char mqtt_server[32] = "";
10
-const char* mqtt_server_int = "192.168.0.1";
11
-const char* mqtt_server_ext = "a.domain.tld";
10
+const char* mqtt_server_int = "192.168.1.33";
11
+const char* mqtt_server_ext = "sg.kawi.fr";
12 12
 const char* mqtt_topic = "topicDHT";
13 13
 const int   mqtt_port = 1883;
14 14
 // The client id identifies the ESP8266 device. Think of it a bit like a hostname (Or just a name, like Greg).
... ...
@@ -16,14 +16,16 @@ char clientID[22] = "";
16 16
 const char* clientIDFmt="esp-%s";
17 17
 
18 18
 const char* mqtt_user="esp8266";
19
-const char* mqtt_password="SomeRandomPassword";
19
+const char* mqtt_password="NjWxXrEMnOeaNtv8b40u";
20 20
 
21 21
 // Initialise the WiFi and MQTT Client objects
22 22
 WiFiClient wifiClient;
23 23
 PubSubClient client(mqtt_server, 1883, wifiClient); // 1883 is the listener port for the Broker
24 24
 
25 25
 void mqtt_connect() {
26
-  if( 0 == strcmp(aplist[currentAPIndex].ssid,"wifi1") ) {
26
+  // Connect to MQTT Broker
27
+  // client.connect returns a boolean value to let us know if the connection was successful.
28
+  if( 0 == strcmp(aplist[currentAPIndex].ssid,"kawifi") ) {
27 29
     //House Wifi
28 30
     client.setServer(mqtt_server_int, mqtt_port);
29 31
     //if (client.connect(clientID)) {
... ...
@@ -53,4 +55,5 @@ void mqtt_reconnect() {
53 55
     count++;
54 56
   }
55 57
 }
58
+#endif //USE_MQTT
56 59
 #endif //_MQTT_H
+45 -43
my_ota.h
... ...
@@ -1,43 +1,45 @@
1
-#ifndef _MY_OTA_H
2
-#define _MY_OTA_H
3
-
4
-#include <ArduinoOTA.h>
5
-
6
-void ota_set() {
7
-  #ifdef USE_OTA
8
-  //ArduinoOTA.setPort(8266);
9
-  //ArduinoOTA.setHostname(clientID);
10
-  //ArduinoOTA.setPassword(WiFi.macAddress().c_str());
11
-  ArduinoOTA.onStart([]() {
12
-    String type;
13
-    displaySetStatus(1);
14
-    if (ArduinoOTA.getCommand() == U_FLASH) {
15
-      type = "sketch";
16
-    } else { // U_FS
17
-      type = "filesystem";
18
-    }
19
-
20
-    // NOTE: if updating FS this would be the place to unmount FS using FS.end()
21
-    Serial.println("Start updating " + type);
22
-  });
23
-  ArduinoOTA.onEnd([]() {
24
-    Serial.println("\nEnd");
25
-    draw("DONE.", -1, -1, 100);
26
-  });
27
-  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
28
-    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
29
-    draw("Upgrading....", -1, -1, (progress / (total / 100)));
30
-  });
31
-  ArduinoOTA.onError([](ota_error_t error) {
32
-    Serial.printf("Error[%u]: ", error);
33
-    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
34
-    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
35
-    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
36
-    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
37
-    else if (error == OTA_END_ERROR) Serial.println("End Failed");
38
-  });
39
-  ArduinoOTA.begin();
40
-  #endif //USE_OTA
41
-}
42
-
43
-#endif //_MY_OTA_H
1
+#ifndef _MY_OTA_H
2
+#define _MY_OTA_H
3
+
4
+#ifdef USE_OTA
5
+#include <ArduinoOTA.h>
6
+#endif //USE_OTA
7
+
8
+void ota_set() {
9
+  #ifdef USE_OTA
10
+  //ArduinoOTA.setPort(8266);
11
+  //ArduinoOTA.setHostname(clientID);
12
+  //ArduinoOTA.setPassword(WiFi.macAddress().c_str());
13
+  ArduinoOTA.onStart([]() {
14
+    String type;
15
+    displaySetStatus(1);
16
+    if (ArduinoOTA.getCommand() == U_FLASH) {
17
+      type = "sketch";
18
+    } else { // U_FS
19
+      type = "filesystem";
20
+    }
21
+
22
+    // NOTE: if updating FS this would be the place to unmount FS using FS.end()
23
+    Serial.println("Start updating " + type);
24
+  });
25
+  ArduinoOTA.onEnd([]() {
26
+    Serial.println("\nEnd");
27
+    draw("DONE.", -1, -1, 100);
28
+  });
29
+  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
30
+    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
31
+    draw("Upgrading....", -1, -1, (progress / (total / 100)));
32
+  });
33
+  ArduinoOTA.onError([](ota_error_t error) {
34
+    Serial.printf("Error[%u]: ", error);
35
+    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
36
+    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
37
+    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
38
+    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
39
+    else if (error == OTA_END_ERROR) Serial.println("End Failed");
40
+  });
41
+  ArduinoOTA.begin();
42
+  #endif //USE_OTA
43
+}
44
+
45
+#endif //_MY_OTA_H