ESP8266 은 SPIFFS라는게 있는데 

인터넷에 있는 자료는

이걸 설명하는데 기초 지식을

무시하고 있다...


검색하면 많은 정보가 나오지만 ...


가장 중요한 기초 정보를 여기에 설명


ESP8266은 내부 FLASH가 없다

대신 칩 외부에 8핀 SPI EEPROM이  별도로 부착되어 있는데

이 롬의 사이즈는 512K, 1M, 4M 등이 있다

많이 보이는 ESP-01은 25Q80H 라고 적힌 칩이 부착되어 있다.

이녀석은 사이즈가 1Mbyte 이다.


SPIFFS는 무슨 의미인가 ?

ESP8266 옆에 붙은 8핀 EEPROM을 어떻게 사용할 것인가 하는 것.


통상의 ESP-01에 붙은 25Q80H를 예를들면 이롬의 1M Byte 중 얼마를 SPIFFS에 할당할 것인가는

아두이노 메뉴에서 TOOL-> FLASH SIZE -> 에서 고르면 된다.

1M (no SPIFFS) 또는 1M(256K SPIFFS) 중 하나를 고르면 우리가 하드를 파티션으로 나누듯 

FLASH EEPROM을 SPIFFS와 그외 영역으로 나누어 준다.

(이외의 설명은 인터넷에 널렸으므로 그걸 참조하시길)


그럼 SPIFFS를 사용하는예제


작성하는 스케치화일이 저장된 폴더에 "data" 폴더를 만들고 그안에 필요한 화일들을 넣어 두면 

TOOL->ESP8266 Skectch Data Uplaod 를 이용하여 SPIFFS 영역에 올려준다.


주의 :

1. SPIFFS로 올라간 화일의 크기는 data 폴더에 있는 화일의 크기 보다 크다.

2. 올리기 에러가 나는 경우 data 폴더내의 파일이 SPIFFS 영역보다 클때 난다.

3. 업로딩 툴 다운후 설치 : 클릭!!!

  

아래는 예제.


1. SPIFFS 나누는 화면 (우측에서 선택하는 대로 SPIFFS 영역이 생성된다)


2. 실행화면


3. 예제 (SPIFFS에 그림을 넣고 웹에서 보여주기)


// ============================================================================================
// https://circuits4you.com/2018/01/31/upload-image-png-jpeg-to-esp8266-web-page/
// ============================================================================================
// ESP8266 SPIFFS HTML Web Page with JPEG, PNG Image 
// ============================================================================================
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>                                   // Include File System Headers
const char* imagefile = "/image.png";
const char* htmlfile = "/index.html";
//ESP AP Mode configuration
const char *ssid = "iptimexxxx";
const char *password = "xxxxxxxxx";
ESP8266WebServer server(80);
// ============================================================================================
void handleRoot(){
  server.sendHeader("Location", "/index.html",true);   //Redirect to our html web page
  server.send(302, "text/plane","");
}
// ============================================================================================
void handleWebRequests(){
  if(loadFromSpiffs(server.uri())) return;
  String message = "File Not Detected\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " NAME:"+server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  Serial.println(message);
}
// ============================================================================================
void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  SPIFFS.begin();                       // Initialize File System
  Serial.println("File System Initialized");
  /*
  WiFi.softAP(ssid);                  // Initialize AP Mode - Password not used
  IPAddress myIP = WiFi.softAPIP(); // it result IP tp 192.168.4.1 ??!!!
  Serial.print("Web Server IP:");
  Serial.println(myIP);  */
  WiFi.begin(ssid, password);          // Connect to your WiFi router
  Serial.println("");
  while (WiFi.status() != WL_CONNECTED) {   // Wait for connection
    delay(500);
    Serial.print(".");
  }
  Serial.print("Web Server IP: ");
  Serial.println(WiFi.localIP());     // IP address assigned to your ESP
  server.on("/",handleRoot);            // Initialize Webserver
  server.onNotFound(handleWebRequests); // Set setver all paths are not found so we can handle as per URI
  server.begin();  
}
// ============================================================================================
void loop() {
 server.handleClient();
}
// ============================================================================================
bool loadFromSpiffs(String path){
  String dataType = "text/plain";
  if(path.endsWith("/")) path += "index.htm";

  if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if(path.endsWith(".html")) dataType = "text/html";
  else if(path.endsWith(".htm")) dataType = "text/html";
  else if(path.endsWith(".css")) dataType = "text/css";
  else if(path.endsWith(".js")) dataType = "application/javascript";
  else if(path.endsWith(".png")) dataType = "image/png";
  else if(path.endsWith(".gif")) dataType = "image/gif";
  else if(path.endsWith(".jpg")) dataType = "image/jpeg";
  else if(path.endsWith(".ico")) dataType = "image/x-icon";
  else if(path.endsWith(".xml")) dataType = "text/xml";
  else if(path.endsWith(".pdf")) dataType = "application/pdf";
  else if(path.endsWith(".zip")) dataType = "application/zip";
  File dataFile = SPIFFS.open(path.c_str(), "r");
  if (server.hasArg("download")) dataType = "application/octet-stream";
  if (server.streamFile(dataFile, dataType) != dataFile.size()) {
  }
  dataFile.close();
  return true;
}
// ============================================================================================

https://circuits4you.com/2018/01/31/upload-image-png-jpeg-to-esp8266-web-page/

'IoT_ESP8266' 카테고리의 다른 글

jQuery 사용하기  (0) 2019.01.13
ESP8266 - AP mode로 LED 원격제어  (0) 2019.01.08
ESp-01 : 원격 TV ON/OFF 리모콘 제어  (1) 2019.01.02
ESP-01 : 서버 LED ON/OFF - 고정 IP  (0) 2019.01.01
ESP-01 : 서버로 LED ON/OFF  (0) 2019.01.01
블로그 이미지

DIYworld

,