Browse Source

[GarageDoor] Move autoupdate to ifdef WITH_AUTOUPDATE

master
Steven Haigh 2 months ago
parent
commit
a9a7258dd6
1 changed files with 19 additions and 32 deletions
  1. 19
    32
      GarageDoor/src/GarageDoor.ino

+ 19
- 32
GarageDoor/src/GarageDoor.ino View File

@@ -4,6 +4,12 @@
4 4
 #include <ESP8266httpUpdate.h>
5 5
 #include <SimpleTimer.h>
6 6
 #include <PubSubClient.h>
7
+
8
+// Comment out the following line to build without HTTP autoupdate.
9
+#define WITH_AUTOUPDATE
10
+#ifdef WITH_AUTOUPDATE
11
+#include <../../autoupdate.h>
12
+#endif
7 13
  
8 14
 // USER CONFIGURED SECTION START //
9 15
 const char* ssid = "YOURSSID";
@@ -61,10 +67,18 @@ void onGotIP(const WiFiEventStationModeGotIP& event){
61 67
 	update_status += WiFi.localIP().toString();
62 68
 	update_status += "\n";
63 69
 	current_state = STATE_UNKNOWN;
64
-	timer.setTimeout(1000, checkForUpdate);
70
+	#ifdef WITH_AUTOUPDATE
71
+	timer.setTimeout(1000, UpdateTimer);
72
+	#endif
65 73
 	Serial.print(millis()); Serial.println(": onGotIP completed");
66 74
 }
67 75
 
76
+#ifdef WITH_AUTOUPDATE
77
+void UpdateTimer() {
78
+	update_status = checkForUpdate();
79
+}
80
+#endif
81
+
68 82
 void setup() {
69 83
 	Serial.begin(115200);
70 84
 	mConnectHandler = WiFi.onStationModeConnected(onConnected);
@@ -73,7 +87,7 @@ void setup() {
73 87
 
74 88
 	WiFi.disconnect() ;
75 89
 	WiFi.persistent(false);
76
-	WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
90
+	WiFi.setSleepMode(WIFI_NONE_SLEEP);
77 91
 	// TX Powers vs Modes:
78 92
 	// 802.11 b: +20 dBm (100mW)
79 93
 	// 802.11 g: +17 dBm (50mW)
@@ -96,7 +110,9 @@ void setup() {
96 110
 	client.setCallback(callback);
97 111
 
98 112
 	timer.setInterval(1000, DetectState);
99
-	timer.setInterval(1000 * 60 * 60 * 8, checkForUpdate);	// Check for updates every 8 hours (1000ms * 60 secs * 60 mins * 8 hours)
113
+	#ifdef WITH_AUTOUPDATE
114
+	timer.setInterval(1000 * 60 * 60 * 8, UpdateTimer);	// Check for updates every 8 hours (1000ms * 60 secs * 60 mins * 8 hours)
115
+	#endif
100 116
 }
101 117
 
102 118
 void loop() {
@@ -211,35 +227,6 @@ void DetectState() {
211 227
 	downChanges = 0;
212 228
 }
213 229
 
214
-void checkForUpdate() {
215
-	update_status = millis();
216
-	update_status += F(": Checking for update...\n");
217
-	BearSSL::WiFiClientSecure UpdateClient;
218
-	UpdateClient.setInsecure();
219
-
220
-	t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("https://10.1.1.93/arduino/update/"));
221
-
222
-	update_status += millis();
223
-	update_status += F(": Returned: ");
224
-	switch(result) {
225
-		case HTTP_UPDATE_FAILED:
226
-			update_status += F("Update failed:\nLastError: ");
227
-			update_status += ESPhttpUpdate.getLastError();
228
-			update_status += F("\nError: ");
229
-			update_status += ESPhttpUpdate.getLastErrorString().c_str();
230
-			update_status += F("\n");
231
-			break;
232
-
233
-		case HTTP_UPDATE_NO_UPDATES:
234
-			update_status += F("No Update Available.\n");
235
-			break;
236
-
237
-		case HTTP_UPDATE_OK:
238
-			update_status += F("Updated OK.\n");
239
-			break;
240
-	}
241
-}
242
-
243 230
 void callback(char* topic, byte* payload, unsigned int length) {
244 231
 	String newTopic = topic;
245 232
 	payload[length] = '\0';

Loading…
Cancel
Save