Can you help me out to understand if this is possible with ESP8266 / 32 ?
I have a main binary that i upload to the chip, let's call it A - that's done from arduino.
A starts to work, but communicates every couple of minutes with central server polling for a task.
If there is a task - let's call it B
A downloads it and stores it on SPIFFS.
Now what should happen is that A uploads it, reboots and B starts to work.
When B finishes it loads up again A and the circle closes - this process goes on forever.
Questions:
1) Is it possible that a stored on SPIFFS binary file can be uploaded to the chip? Like OTA does via www.
2) Can i somehow store A onto the SPIFFS, so that when B finishes i reupload A ?
Thanks for any input into this
-
why don't you have a single program that does both A and B?jsotola– jsotola2019年01月05日 23:18:13 +00:00Commented Jan 5, 2019 at 23:18
-
Look at what ArduinoOTA does.Majenko– Majenko2019年01月05日 23:19:23 +00:00Commented Jan 5, 2019 at 23:19
-
@Majenko - right, but i would then have to ask for firmware via WWW i don't speak to Web server, i download the binary from a dedicated grid computing system. So maybe you know if i can i download binary to SPIFFS and upload to chip other way than OTA?PeeS– PeeS2019年01月05日 23:44:22 +00:00Commented Jan 5, 2019 at 23:44
-
@jsotola because B changes and is sent from a distributed system, has nothing to do with A. Binaries sent from distributed system will be different all the time.PeeS– PeeS2019年01月05日 23:44:53 +00:00Commented Jan 5, 2019 at 23:44
-
2Look at what ArduinoOTA does. I say again. Look at what it does. Don't use it. Just look at what it does.Majenko– Majenko2019年01月05日 23:45:40 +00:00Commented Jan 5, 2019 at 23:45
2 Answers 2
The esp8266 Arduino package has 3 libraries for firmware update.
- ArduinoOTA for upload from Arduino IDE
- ESP8266HTTPUpdateServer for upload with web browser
- ESP8266httpUpdate library to check a web server for new version of the firmware
I think i've found an answer to my question here
https://www.esp8266.com/viewtopic.php?f=32&t=11324
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "FS.h"
void setup() {
Serial.begin(115200);
Serial.println();
SPIFFS.begin();
Dir dir = SPIFFS.openDir("/");
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, LOW);
File file = SPIFFS.open("/blinkESP.bin", "r");
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace, U_FLASH)) { //start with max available size
Update.printError(Serial);
Serial.println("ERROR");
}
while (file.available()) {
uint8_t ibuffer[128];
file.read((uint8_t *)ibuffer, 128);
Serial.println((char *)ibuffer);
Update.write(ibuffer, sizeof(ibuffer));
}
Serial.print(Update.end(true));
digitalWrite(BUILTIN_LED, HIGH);
file.close();
}
void loop() {
}
Will give it a try and revert back to confirm if it answers my question.
-
Confirmed,works like a charm. Flashes firmware with a file from SPIFFS.PeeS– PeeS2019年01月19日 20:10:13 +00:00Commented Jan 19, 2019 at 20:10