mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
* Deprecate SPIFFS, move examples to LittleFS SPIFFS has been a great filesystem, but it has significant problems in many cases (and it's also pretty slow). Development seems to have slowed/stopped on the upstream version, and we're not able to provide support or fix the known issues with it as-is. Deprecate SPIFFS variable. Update all examples to use LittleFS instead of SPIFFS. Also, minor cleanup on very old examples which has obsolete delays waiting for the Serial port to come up, or which were stuck at 9600 baud because of their ancient AVR heritage. Fixes #7095 * Remove leftover debug code * Clean up comments in some examples * Update documentation on SPIFFS deprecation * Fix host tests to avoid deprecation warnings * Fix cut-n-paste error * Restore SpeedTest.ino, adjust to allow custom FSes Co-authored-by: Develo <deveyes@gmail.com>
101 lines
2.5 KiB
C++
101 lines
2.5 KiB
C++
/**
|
|
httpUpdate.ino
|
|
|
|
Created on: 27.11.2015
|
|
|
|
*/
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266WiFiMulti.h>
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
#include <ESP8266httpUpdate.h>
|
|
|
|
#ifndef APSSID
|
|
#define APSSID "APSSID"
|
|
#define APPSK "APPSK"
|
|
#endif
|
|
|
|
ESP8266WiFiMulti 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(APSSID, APPSK);
|
|
|
|
|
|
}
|
|
|
|
void update_started() {
|
|
Serial.println("CALLBACK: HTTP update process started");
|
|
}
|
|
|
|
void update_finished() {
|
|
Serial.println("CALLBACK: HTTP update process finished");
|
|
}
|
|
|
|
void update_progress(int cur, int total) {
|
|
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
|
|
}
|
|
|
|
void update_error(int err) {
|
|
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
|
|
}
|
|
|
|
|
|
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
|
|
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
|
|
|
// Add optional callback notifiers
|
|
ESPhttpUpdate.onStart(update_started);
|
|
ESPhttpUpdate.onEnd(update_finished);
|
|
ESPhttpUpdate.onProgress(update_progress);
|
|
ESPhttpUpdate.onError(update_error);
|
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "http://server/file.bin");
|
|
// Or:
|
|
//t_httpUpdate_return ret = ESPhttpUpdate.update(client, "server", 80, "file.bin");
|
|
|
|
switch (ret) {
|
|
case HTTP_UPDATE_FAILED:
|
|
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
|
break;
|
|
|
|
case HTTP_UPDATE_NO_UPDATES:
|
|
Serial.println("HTTP_UPDATE_NO_UPDATES");
|
|
break;
|
|
|
|
case HTTP_UPDATE_OK:
|
|
Serial.println("HTTP_UPDATE_OK");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|