Browse Source

Add autoupdate.h as a common file for all projects

master
Steven Haigh 2 months ago
parent
commit
fb7b4cfe16

+ 2
- 2
ClimateControl/platformio.ini View File

@@ -10,8 +10,8 @@
10 10
 
11 11
 [env:d1_mini]
12 12
 board_build.f_cpu = 160000000L
13
-platform = espressif8266
14
-;platform = https://github.com/platformio/platform-espressif8266.git
13
+;platform = espressif8266
14
+platform = https://github.com/platformio/platform-espressif8266.git
15 15
 ;platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
16 16
 board = d1_mini
17 17
 framework = arduino

+ 6
- 13
GarageDoor/src/GarageDoor.ino View File

@@ -4,8 +4,6 @@
4 4
 #include <ESP8266httpUpdate.h>
5 5
 #include <SimpleTimer.h>
6 6
 #include <PubSubClient.h>
7
-#include <lwip/netif.h>
8
-#include <lwip/etharp.h>
9 7
  
10 8
 // USER CONFIGURED SECTION START //
11 9
 const char* ssid = "YOURSSID";
@@ -76,7 +74,12 @@ void setup() {
76 74
 	WiFi.disconnect() ;
77 75
 	WiFi.persistent(false);
78 76
 	WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
79
-	WiFi.setPhyMode(WIFI_PHY_MODE_11N); // PHY_MODE_11B, PHY_MODE_11G, PHY_MODE_11N
77
+	// TX Powers vs Modes:
78
+	// 802.11 b: +20 dBm (100mW)
79
+	// 802.11 g: +17 dBm (50mW)
80
+	// 802.11 n: +14 dBm (25mW)
81
+	// PHY_MODE_11B, PHY_MODE_11G, PHY_MODE_11N
82
+	WiFi.setPhyMode(WIFI_PHY_MODE_11G);	// Switch to 802.11g to get max range.
80 83
 	WiFi.mode(WIFI_STA);		// Client mode
81 84
 	WiFi.setOutputPower(18);	// 10dBm == 10mW, 14dBm = 25mW, 17dBm = 50mW, 20dBm = 100mW
82 85
 	WiFi.begin(ssid, password);	// Start WiFi.
@@ -94,7 +97,6 @@ void setup() {
94 97
 
95 98
 	timer.setInterval(1000, DetectState);
96 99
 	timer.setInterval(1000 * 60 * 60 * 8, checkForUpdate);	// Check for updates every 8 hours (1000ms * 60 secs * 60 mins * 8 hours)
97
-	timer.setInterval(5000, GratuitousARPTask);
98 100
 }
99 101
 
100 102
 void loop() {
@@ -275,12 +277,3 @@ void reboot() {
275 277
 	delay(100);
276 278
 	ESP.restart();
277 279
 }
278
-
279
-void GratuitousARPTask() {
280
-	netif *n = netif_list;
281
-
282
-	while (n) {
283
-		etharp_gratuitous(n);
284
-		n = n->next;
285
-	}
286
-}

+ 1
- 13
OutsideMonitor/src/GPIO_MQTT.ino View File

@@ -6,8 +6,6 @@
6 6
 #include <ESP8266HTTPUpdateServer.h>
7 7
 #include <SimpleTimer.h>
8 8
 #include <dht.h>
9
-#include <lwip/netif.h>
10
-#include <lwip/etharp.h>
11 9
 
12 10
 //USER CONFIGURED SECTION START//
13 11
 const char* ssid = "YOURSSID";
@@ -78,7 +76,7 @@ void setup() {
78 76
 
79 77
 	WiFi.disconnect() ;
80 78
 	WiFi.persistent(false);
81
-	WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
79
+	WiFi.setSleepMode(WIFI_NONE_SLEEP);
82 80
 	WiFi.mode(WIFI_STA);		// Client mode
83 81
 	WiFi.setOutputPower(18);	// 10dBm == 10mW, 14dBm = 25mW, 17dBm = 50mW, 20dBm = 100mW
84 82
 	WiFi.begin(ssid, password);	// Start WiFi.
@@ -93,7 +91,6 @@ void setup() {
93 91
 
94 92
 	timer.setInterval(4 * 60 * 60 * 1000, checkForUpdate);
95 93
 	timer.setInterval(30000, CheckTemps);
96
-	timer.setInterval(5000, GratuitousARPTask);
97 94
 	CheckTemps();
98 95
 }
99 96
 
@@ -287,12 +284,3 @@ void SetGPIO(uint8_t gpio, String DxValue) {
287 284
 		Serial.print("Setting GPIO pin "); Serial.print(pins[gpio]); Serial.println(" to LOW");
288 285
 	}
289 286
 }
290
-
291
-void GratuitousARPTask() {
292
-	netif *n = netif_list;
293
-
294
-	while (n) {
295
-		etharp_gratuitous(n);
296
-		n = n->next;
297
-	}
298
-}

+ 6
- 12
Roomba/src/Roomba.ino View File

@@ -5,8 +5,6 @@
5 5
 #include <ESP8266httpUpdate.h>
6 6
 #include <ESP8266HTTPUpdateServer.h>
7 7
 #include <SimpleTimer.h>
8
-#include <lwip/netif.h>
9
-#include <lwip/etharp.h>
10 8
 
11 9
 // Comment out the following define to not build in the automatic web update bits.
12 10
 #define WITH_AUTOUPDATE
@@ -65,6 +63,7 @@ void onConnected(const WiFiEventStationModeConnected& event){
65 63
 	update_status += millis();
66 64
 	update_status += ": Connected to AP.";
67 65
 	update_status += "\n";
66
+	current_state = STATE_UNKNOWN;
68 67
 }
69 68
 
70 69
 void onDisconnect(const WiFiEventStationModeDisconnected& event){
@@ -93,7 +92,7 @@ void setup() {
93 92
 	WiFi.disconnect() ;
94 93
 	WiFi.persistent(false);
95 94
 	WiFi.mode(WIFI_STA);		// Client mode
96
-	WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
95
+	WiFi.setSleepMode(WIFI_NONE_SLEEP);
97 96
 	WiFi.setOutputPower(18);	// 10dBm == 10mW, 14dBm = 25mW, 17dBm = 50mW, 20dBm = 100mW
98 97
 	WiFi.begin(ssid, password);	// Start WiFi.
99 98
 
@@ -113,7 +112,6 @@ void setup() {
113 112
 
114 113
 	timer.setInterval(10000, getSensors);
115 114
 	timer.setInterval(59000, StayAwake);
116
-	timer.setInterval(5000, GratuitousARPTask);
117 115
 #ifdef WITH_AUTOUPDATE
118 116
 	timer.setInterval(4 * 60 * 60 * 1000, checkForUpdate);	// Check for update every 4 hours.
119 117
 #endif
@@ -209,6 +207,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
209 207
 void getSensors() {
210 208
 	if ( ! client.connected() ) {
211 209
 		current_state = STATE_UNKNOWN;
210
+		status = "";
212 211
 		return;
213 212
 	}
214 213
 
@@ -239,6 +238,7 @@ void getSensors() {
239 238
 	// 26 (2 byte reply) - battery capacity
240 239
 	byte command[] = { 128, 149, 1, 3 };
241 240
 	SendCommandList( command, 4 );
241
+	delay(10);
242 242
 
243 243
 	// We should get 10 bytes back.
244 244
 	i = 0;
@@ -256,6 +256,8 @@ void getSensors() {
256 256
 	if ( i == 0 ) {
257 257
 		status_log += "ERROR: No response\n";
258 258
 		client.publish("roomba/status", "Not Responding");
259
+		current_state = STATE_UNKNOWN;
260
+		status = "";
259 261
 		return;
260 262
 	}
261 263
 
@@ -451,11 +453,3 @@ void SendCommandList( byte *ptr, byte len ) {
451 453
 	status_log += "\n";
452 454
 }
453 455
 
454
-void GratuitousARPTask() {
455
-	netif *n = netif_list;
456
-
457
-	while (n) {
458
-		etharp_gratuitous(n);
459
-		n = n->next;
460
-	}
461
-}

+ 38
- 0
autoupdate.h View File

@@ -0,0 +1,38 @@
1
+#ifdef WITH_AUTOUPDATE
2
+String checkForUpdate() {
3
+	String update_status;
4
+	update_status = millis();
5
+
6
+	// Don't run if wifi isn't connected...
7
+	if ( WiFi.status() != WL_CONNECTED ) {
8
+		update_status += F(": Wifi not connected. Skipping update check\n");
9
+		return update_status;
10
+	}
11
+	update_status += F(": Checking for update...\n");
12
+
13
+	BearSSL::WiFiClientSecure UpdateClient;
14
+	UpdateClient.setInsecure();
15
+	t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("https://10.1.1.93/arduino/update/"));
16
+
17
+	//WiFiClient UpdateClient;
18
+	//t_httpUpdate_return result = ESPhttpUpdate.update(UpdateClient, F("http://10.1.1.93/arduino/update/"));
19
+
20
+	switch(result) {
21
+		case HTTP_UPDATE_FAILED:
22
+			update_status += F(" - Update failed: ");
23
+			update_status += ESPhttpUpdate.getLastError();
24
+			update_status += F(" - Error: ");
25
+			update_status += ESPhttpUpdate.getLastErrorString().c_str();
26
+			update_status += F("\n");
27
+			break;
28
+		case HTTP_UPDATE_NO_UPDATES:
29
+			update_status += F(" - No Update Available.\n");
30
+			break;
31
+		case HTTP_UPDATE_OK:
32
+			update_status += F(" - Updated OK.\n");
33
+			break;
34
+	}
35
+
36
+	return update_status;
37
+}
38
+#endif

Loading…
Cancel
Save