Browse Source

[OutsideMonitor] Export autoupdate to #define WITH_AUTOUPDATE

master
Steven Haigh 2 months ago
parent
commit
623d3a3710
1 changed files with 17 additions and 31 deletions
  1. 17
    31
      OutsideMonitor/src/GPIO_MQTT.ino

+ 17
- 31
OutsideMonitor/src/GPIO_MQTT.ino View File

@@ -1,12 +1,16 @@
1 1
 #include <PubSubClient.h>
2 2
 #include <ESP8266WiFi.h>
3 3
 #include <ESP8266WebServer.h>
4
-//#include <ESP8266HTTPClient.h>
5 4
 #include <ESP8266httpUpdate.h>
6 5
 #include <ESP8266HTTPUpdateServer.h>
7 6
 #include <SimpleTimer.h>
8 7
 #include <dht.h>
9 8
 
9
+#define WITH_AUTOUPDATE
10
+#ifdef WITH_AUTOUPDATE
11
+#include <../../autoupdate.h>
12
+#endif
13
+
10 14
 //USER CONFIGURED SECTION START//
11 15
 const char* ssid = "YOURSSID";
12 16
 const char* password = "YOURPASSWORD";
@@ -61,8 +65,16 @@ void onGotIP(const WiFiEventStationModeGotIP& event){
61 65
 	update_status += ": Station connected, IP: ";
62 66
 	update_status += WiFi.localIP().toString();
63 67
 	update_status += "\n";
64
-	timer.setTimeout(1000, checkForUpdate);
68
+	#ifdef WITH_AUTOUPDATE
69
+	timer.setTimeout(1000, UpdateTimer);
70
+	#endif
71
+}
72
+
73
+#ifdef WITH_AUTOUPDATE
74
+void UpdateTimer() {
75
+	update_status = checkForUpdate();
65 76
 }
77
+#endif
66 78
 
67 79
 void setup() {
68 80
 	for ( int i = 0; i < 4; i++ ) {
@@ -89,7 +101,9 @@ void setup() {
89 101
 	client.setServer(mqtt_server, mqtt_port);
90 102
 	client.setCallback(callback);
91 103
 
92
-	timer.setInterval(4 * 60 * 60 * 1000, checkForUpdate);
104
+	#ifdef WITH_AUTOUPDATE
105
+	timer.setInterval(4 * 60 * 60 * 1000, UpdateTimer);
106
+	#endif
93 107
 	timer.setInterval(30000, CheckTemps);
94 108
 	CheckTemps();
95 109
 }
@@ -124,34 +138,6 @@ void loop() {
124 138
 	}
125 139
 }
126 140
 
127
-void checkForUpdate() {
128
-	update_status = F("Checking for update...\n");
129
-
130
-	BearSSL::WiFiClientSecure UpdateClient;
131
-	UpdateClient.setInsecure();
132
-	t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("https://10.1.1.93/arduino/update/"));
133
-
134
-	//WiFiClient UpdateClient;
135
-	//t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("http://10.1.1.93/arduino/update/"));
136
-
137
-	update_status += F("Returned: ");
138
-	switch(result) {
139
-		case HTTP_UPDATE_FAILED:
140
-			update_status += F("Update failed:\nLastError: ");
141
-			update_status += ESPhttpUpdate.getLastError();
142
-			update_status += F("\nError: ");
143
-			update_status += ESPhttpUpdate.getLastErrorString().c_str();
144
-			update_status += F("\n");
145
-			break;
146
-		case HTTP_UPDATE_NO_UPDATES:
147
-			update_status += F("No Update Available.\n");
148
-			break;
149
-		case HTTP_UPDATE_OK:
150
-			update_status += F("Updated OK.\n");
151
-			break;
152
-	}
153
-}
154
-
155 141
 void callback(char* topic, byte* payload, unsigned int length) {
156 142
 	payload[length] = '\0';
157 143
 	String Payload = String((char *)payload);

Loading…
Cancel
Save