Skip to content

Commit

Permalink
Update WebUpdate.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
yuan910715 authored May 11, 2021
1 parent e4f93e6 commit a3f85cb
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions WebUpdate/WebUpdate.ino
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
/*
To upload through terminal you can use: curl -F "[email protected]" esp8266-webupdate.local/update
*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>

#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#define STASSID "WIFINAME"
#define STAPSK "password"
#endif

const char* host = "esp8266-webupdate";
const char* ssid = STASSID;
const char* password = STAPSK;

Expand All @@ -22,8 +16,8 @@ const char* serverIndex = "<form method='POST' action='/update' enctype='multipa

void setup(void) {
Serial.begin(115200);
EEPROM.begin(512);
for (int i = 0; i < 512; i++) {
EEPROM.begin(520);
for (int i = 0; i < 520; i++) {
EEPROM.write(i, 255);
}
EEPROM.end();
Expand All @@ -32,7 +26,7 @@ void setup(void) {
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() == WL_CONNECTED) {
MDNS.begin(host);

server.on("/", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", serverIndex);
Expand All @@ -45,7 +39,7 @@ void setup(void) {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.setDebugOutput(true);
WiFiUDP::stopAll();

Serial.printf("Update: %s\n", upload.filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
Expand All @@ -66,9 +60,9 @@ void setup(void) {
yield();
});
server.begin();
MDNS.addService("http", "tcp", 80);



Serial.printf("Ready! Open http://%s.local in your browser\n", host);
Serial.println("or http://"+WiFi.localIP().toString());

} else {
Expand All @@ -78,5 +72,4 @@ void setup(void) {

void loop(void) {
server.handleClient();
MDNS.update();
}

0 comments on commit a3f85cb

Please sign in to comment.