| 
									
										
										
										
											2018-11-19 16:57:38 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |    httpUpdate.ino | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Created on: 27.11.2015 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Arduino.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <WiFi.h>
 | 
					
						
							|  |  |  | #include <WiFiMulti.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <HTTPClient.h>
 | 
					
						
							|  |  |  | #include <HTTPUpdate.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WiFiMulti WiFiMulti; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void setup() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Serial.begin(115200); | 
					
						
							|  |  |  |   // Serial.setDebugOutput(true);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Serial.println(); | 
					
						
							|  |  |  |   Serial.println(); | 
					
						
							|  |  |  |   Serial.println(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (uint8_t t = 4; t > 0; t--) { | 
					
						
							|  |  |  |     Serial.printf("[SETUP] WAIT %d...\n", t); | 
					
						
							|  |  |  |     Serial.flush(); | 
					
						
							|  |  |  |     delay(1000); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   WiFi.mode(WIFI_STA); | 
					
						
							|  |  |  |   WiFiMulti.addAP("SSID", "PASSWORD"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void loop() { | 
					
						
							|  |  |  |   // wait for WiFi connection
 | 
					
						
							|  |  |  |   if ((WiFiMulti.run() == WL_CONNECTED)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WiFiClient client; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // The line below is optional. It can be used to blink the LED on the board during flashing
 | 
					
						
							|  |  |  |     // The LED will be on during download of one buffer of data from the network. The LED will
 | 
					
						
							|  |  |  |     // be off during writing that buffer to flash
 | 
					
						
							|  |  |  |     // On a good connection the LED should flash regularly. On a bad connection the LED will be
 | 
					
						
							|  |  |  |     // on much longer than it will be off. Other pins than LED_BUILTIN may be used. The second
 | 
					
						
							|  |  |  |     // value is used to put the LED on. If the LED is on with HIGH, that value should be passed
 | 
					
						
							|  |  |  |     // httpUpdate.setLedPin(LED_BUILTIN, LOW);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     t_httpUpdate_return ret = httpUpdate.update(client, "http://server/file.bin"); | 
					
						
							|  |  |  |     // Or:
 | 
					
						
							| 
									
										
										
										
											2020-10-03 01:13:27 +02:00
										 |  |  |     //t_httpUpdate_return ret = httpUpdate.update(client, "server", 80, "/file.bin");
 | 
					
						
							| 
									
										
										
										
											2018-11-19 16:57:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     switch (ret) { | 
					
						
							|  |  |  |       case HTTP_UPDATE_FAILED: | 
					
						
							| 
									
										
										
										
											2018-12-06 18:50:53 +01:00
										 |  |  |         Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); | 
					
						
							| 
									
										
										
										
											2018-11-19 16:57:38 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case HTTP_UPDATE_NO_UPDATES: | 
					
						
							|  |  |  |         Serial.println("HTTP_UPDATE_NO_UPDATES"); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case HTTP_UPDATE_OK: | 
					
						
							|  |  |  |         Serial.println("HTTP_UPDATE_OK"); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |