Hey all, I'm trying to download a file(jpg) and store it in SPIFFS to later be used to draw using JPEGdecoder library
SPIFFS is constant, so Node really only needs to download the image the first time it's on.
Just need an efficient way to grab the image from HTTP - Store it in SPIFFS
The code I'm using below (just a part of larger project) - trying to read the JPG line by line and write it line by line to SPIFFS is in-elegant I know. Here for ideas
Thanks!
#include "FS.h"
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;
void setup() {
Serial.begin(9600);
//SPIFFS.format();
// always use this to "mount" the filesystem
bool result = SPIFFS.begin();
Serial.println("SPIFFS opened: " + result);
// this opens the file "test.jpg" in read-mode
File f = SPIFFS.open("/test.jpg", "r");
if (!f) {
Serial.println("File doesn't exist yet. Grabbing it");
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("SSID", "Password");
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
const uint16_t port = 80;
const char * host = "13.238.161.58"; // ip or dns
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(5000);
return;
}
// This will send the request to the server
client.println("GET /test.jpg");
//read back one line from server
String line = client.readStringUntil('\r');
//Serial.println(line);
//SPIFFS.open("/test.jpg", "r");
f.println(line);
Serial.println("closing connection");
client.stop();
Serial.println("wait 5 sec...");
delay(5000);
}
else {
// we could open the file
while(f.available()) {
//Lets read line by line from the file
String line = f.readStringUntil('n');
Serial.println(line);
}
}
f.close();
}
void loop() {
// nothing to do for now, this is just a simple test
}
Taking advantage of the subject, how does this code work? You need to download jpg or .raw images to a folder named 'data' as in the Bodmer sketch here: NodeMCU (ESP8266) + ILI9341 TFT + SPIFFS = easy image storage and display - Displays - Arduino Forum
I would very much like to attach several images to Nodemcu's SPIFFS and display in a tft display like slideshow, for example.
If anyone can put it here, I appreciate it.
Dancopy:
Taking advantage of the subject, how does this code work? You need to download jpg or .raw images to a folder named 'data' as in the Bodmer sketch here: NodeMCU (ESP8266) + ILI9341 TFT + SPIFFS = easy image storage and display - Displays - Arduino Forum
I would very much like to attach several images to Nodemcu's SPIFFS and display in a tft display like slideshow, for example.
If anyone can put it here, I appreciate it.