mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-10-31 15:50:55 +03:00 
			
		
		
		
	This ESP8266HTTPUpdateServer can be instantiated and used more cleanly, it's also able to take or create an ESP8266WebServer to configure the events and /update handler. It's been made more robust by handling upload abort, which depends on fix provided for issue #833
		
			
				
	
	
		
			44 lines
		
	
	
		
			1001 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1001 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|   To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update
 | |
| */
 | |
| 
 | |
| #include <ESP8266WiFi.h>
 | |
| #include <WiFiClient.h>
 | |
| #include <ESP8266WebServer.h>
 | |
| #include <ESP8266mDNS.h>
 | |
| #include <ESP8266HTTPUpdateServer.h>
 | |
| 
 | |
| const char* host = "esp8266-webupdate";
 | |
| const char* ssid = "........";
 | |
| const char* password = "........";
 | |
| 
 | |
| ESP8266WebServer httpServer(80);
 | |
| ESP8266HTTPUpdateServer httpUpdater;
 | |
| 
 | |
| void setup(void){
 | |
| 
 | |
|   Serial.begin(115200);
 | |
|   Serial.println();
 | |
|   Serial.println("Booting Sketch...");
 | |
|   WiFi.mode(WIFI_AP_STA);
 | |
|   WiFi.begin(ssid, password);
 | |
| 
 | |
|   while(WiFi.waitForConnectResult() != WL_CONNECTED){
 | |
|     WiFi.begin(ssid, password);
 | |
|     Serial.println("WiFi failed, retrying.");
 | |
|   }
 | |
| 
 | |
|   MDNS.begin(host);
 | |
| 
 | |
|   httpUpdater.setup(&httpServer);
 | |
|   httpServer.begin();
 | |
| 
 | |
|   MDNS.addService("http", "tcp", 80);
 | |
|   Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
 | |
| }
 | |
| 
 | |
| void loop(void){
 | |
|   httpServer.handleClient();
 | |
|   delay(1);
 | |
| }
 |