Browse Source

[Roomba] Move auto updates to #define WITH_AUTOUPDATE

master
Steven Haigh 2 months ago
parent
commit
f9d59ce56d
1 changed files with 11 additions and 39 deletions
  1. 11
    39
      Roomba/src/Roomba.ino

+ 11
- 39
Roomba/src/Roomba.ino View File

@@ -1,13 +1,15 @@
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
 
9 8
 // Comment out the following define to not build in the automatic web update bits.
10 9
 #define WITH_AUTOUPDATE
10
+#ifdef WITH_AUTOUPDATE
11
+#include <../../autoupdate.h>
12
+#endif
11 13
 
12 14
 // USER CONFIGURED SECTION START //
13 15
 const char* ssid = "YOURSSID";
@@ -80,10 +82,16 @@ void onGotIP(const WiFiEventStationModeGotIP& event){
80 82
 	update_status += WiFi.localIP().toString();
81 83
 	update_status += "\n";
82 84
 #ifdef WITH_AUTOUPDATE
83
-	timer.setTimeout(1000, checkForUpdate);
85
+	timer.setTimeout(1000, UpdateTimer);
84 86
 #endif
85 87
 }
86 88
 
89
+#ifdef WITH_AUTOUPDATE
90
+void UpdateTimer() {
91
+	update_status = checkForUpdate();
92
+}
93
+#endif
94
+
87 95
 void setup() {
88 96
 	mConnectHandler = WiFi.onStationModeConnected(onConnected);
89 97
 	mDisConnectHandler = WiFi.onStationModeDisconnected(onDisconnect);
@@ -113,7 +121,7 @@ void setup() {
113 121
 	timer.setInterval(10000, getSensors);
114 122
 	timer.setInterval(59000, StayAwake);
115 123
 #ifdef WITH_AUTOUPDATE
116
-	timer.setInterval(4 * 60 * 60 * 1000, checkForUpdate);	// Check for update every 4 hours.
124
+	timer.setInterval(4 * 60 * 60 * 1000, UpdateTimer);	// Check for update every 4 hours.
117 125
 #endif
118 126
 }
119 127
 
@@ -137,42 +145,6 @@ void loop() {
137 145
 	delay(50);
138 146
 }
139 147
 
140
-#ifdef WITH_AUTOUPDATE
141
-void checkForUpdate() {
142
-	update_status = millis();
143
-
144
-	// Don't run if wifi isn't connected...
145
-	if ( WiFi.status() != WL_CONNECTED ) {
146
-		update_status += F(": Wifi not connected. Skipping update check\n");
147
-		return;
148
-	}
149
-	update_status += F(": Checking for update...\n");
150
-
151
-	BearSSL::WiFiClientSecure UpdateClient;
152
-	UpdateClient.setInsecure();
153
-	t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("https://10.1.1.93/arduino/update/"));
154
-
155
-	//WiFiClient UpdateClient;
156
-	//t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("http://10.1.1.93/arduino/update/"));
157
-
158
-	switch(result) {
159
-		case HTTP_UPDATE_FAILED:
160
-			update_status += F(" - Update failed: ");
161
-			update_status += ESPhttpUpdate.getLastError();
162
-			update_status += F(" - Error: ");
163
-			update_status += ESPhttpUpdate.getLastErrorString().c_str();
164
-			update_status += F("\n");
165
-			break;
166
-		case HTTP_UPDATE_NO_UPDATES:
167
-			update_status += F(" - No Update Available.\n");
168
-			break;
169
-		case HTTP_UPDATE_OK:
170
-			update_status += F(" - Updated OK.\n");
171
-			break;
172
-	}
173
-}
174
-#endif
175
-
176 148
 //Functions
177 149
 void callback(char* topic, byte* payload, unsigned int length) {
178 150
 	String newTopic = topic;

Loading…
Cancel
Save