Browse Source

[RGB Lights] Ship out auto updates to define WITH_AUTOUPDATE

master
Steven Haigh 1 month ago
parent
commit
10467b1e36
1 changed files with 17 additions and 45 deletions
  1. 17
    45
      RGB Lights/src/ESP_MQTT_Digital_LEDs.ino

+ 17
- 45
RGB Lights/src/ESP_MQTT_Digital_LEDs.ino View File

@@ -1,13 +1,16 @@
1 1
 #include <ESP8266WiFi.h>
2 2
 #include <ESP8266WebServer.h>
3 3
 #include <ESP8266httpUpdate.h>
4
-//#include <ESP8266HTTPClient.h>
5 4
 #include <ESP8266HTTPUpdateServer.h>
6 5
 #include <ArduinoJson.h>
7 6
 #include <PubSubClient.h>
8 7
 #include <SimpleTimer.h>
9
-#include <lwip/netif.h>
10
-#include <lwip/etharp.h>
8
+
9
+// Comment out the following line to build without HTTP autoupdate.
10
+#define WITH_AUTOUPDATE
11
+#ifdef WITH_AUTOUPDATE
12
+#include <../../autoupdate.h>
13
+#endif
11 14
 
12 15
 //#define FASTLED_INTERRUPT_RETRY_COUNT 1
13 16
 #define FASTLED_ALLOW_INTERRUPTS 0
@@ -162,11 +165,17 @@ void onGotIP(const WiFiEventStationModeGotIP& event){
162 165
 	update_status += ": Station connected, IP: ";
163 166
 	update_status += WiFi.localIP().toString();
164 167
 	update_status += "\n";
165
-	timer.setTimeout(1000, checkForUpdate);
168
+	#ifdef WITH_AUTOUPDATE
169
+	timer.setTimeout(1000, UpdateTimer);
170
+	#endif
166 171
 	timer.setTimeout(500, sendState);
167 172
 }
168 173
 
169 174
 /********************************** START SETUP*****************************************/
175
+void UpdateTimer() {
176
+	update_status = checkForUpdate();
177
+}
178
+
170 179
 void setup() {
171 180
 	mConnectHandler = WiFi.onStationModeConnected(onConnected);
172 181
 	mDisConnectHandler = WiFi.onStationModeDisconnected(onDisconnect);
@@ -174,7 +183,7 @@ void setup() {
174 183
 
175 184
 	WiFi.disconnect() ;
176 185
 	WiFi.persistent(false);
177
-	WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
186
+	WiFi.setSleepMode(WIFI_NONE_SLEEP);
178 187
 	WiFi.mode(WIFI_STA);		// Client mode
179 188
 	WiFi.setOutputPower(18);	// 10dBm == 10mW, 14dBm = 25mW, 17dBm = 50mW, 20dBm = 100mW
180 189
 	WiFi.begin(ssid, password);	// Start WiFi.
@@ -195,38 +204,10 @@ void setup() {
195 204
 	client.setCallback(callback);
196 205
 
197 206
 	Serial.println("Ready");
198
-	timer.setInterval(4 * 60 * 60 * 1000, checkForUpdate);
207
+	#ifdef WITH_AUTOUPDATE
208
+	timer.setInterval(4 * 60 * 60 * 1000, UpdateTimer);
209
+	#endif
199 210
 	timer.setInterval(10000, timer_10s);
200
-	timer.setInterval(5000, GratuitousARPTask);
201
-}
202
-
203
-void checkForUpdate() {
204
-	update_status = F("Checking for update...\n");
205
-
206
-	BearSSL::WiFiClientSecure UpdateClient;
207
-	UpdateClient.setInsecure();
208
-	t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("https://10.1.1.93/arduino/update/"));
209
-
210
-	//WiFiClient UpdateClient;
211
-	//t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("http://10.1.1.93/arduino/update/"));
212
-	//t_httpUpdate_return result = ESPhttpUpdate.update("10.1.1.93", 80, "/arduino/update/");
213
-
214
-	update_status += F("Returned: ");
215
-	switch(result) {
216
-		case HTTP_UPDATE_FAILED:
217
-			update_status += F("Update failed:\nLastError: ");
218
-			update_status += ESPhttpUpdate.getLastError();
219
-			update_status += F("\nError: ");
220
-			update_status += ESPhttpUpdate.getLastErrorString().c_str();
221
-			update_status += F("\n");
222
-			break;
223
-		case HTTP_UPDATE_NO_UPDATES:
224
-			update_status += F("No Update Available.\n");
225
-			break;
226
-		case HTTP_UPDATE_OK:
227
-			update_status += F("Updated OK.\n");
228
-			break;
229
-	}
230 211
 }
231 212
 
232 213
 void handle_root()
@@ -796,12 +777,3 @@ void temp2rgb(unsigned int kelvin) {
796 777
 		}
797 778
 	}
798 779
 }
799
-
800
-void GratuitousARPTask() {
801
-	netif *n = netif_list;
802
-
803
-	while (n) {
804
-		etharp_gratuitous(n);
805
-		n = n->next;
806
-	}
807
-}

Loading…
Cancel
Save