LoginSignup
5
5

More than 5 years have passed since last update.

ESP8266 > SPIFFS.open()成功

Last updated at Posted at 2016-01-07
動作環境
Arduino IDE 1.6.6
Board Manager URL -  http://arduino.esp8266.com/staging/package_esp8266com_index.json

http://qiita.com/exabugs/items/2f67ae363a1387c8967c
を参考にSPIFFSでのファイル書込みをやってみて成功した。

上記リンクのコメント( http://qiita.com/exabugs/items/2f67ae363a1387c8967c )にて2.0.0でされたことを紹介されていたが、その時点でstagingの2.1.0-rc1をインストールしてしまっていた。

以下のコードでうまく動作した。

#include "FS.h"

void setup() {
  char *chptr;
  Serial.begin(115200);
  Serial.println();

  bool res = SPIFFS.begin();
  if (!res) {
    Serial.println("SPIFFS.begin fail");
    return;
  }

  // 1. write
  File fd = SPIFFS.open("/tmp2.txt", "w");
  if (!fd) {
    Serial.println("open error");
  }
  fd.println("data in file");    
  fd.close();

  // 2. read
  fd = SPIFFS.open("/tmp2.txt", "r");
  String line = fd.readStringUntil('\n');
  Serial.print("file read:");
  Serial.println(line);
  fd.close();
}

void loop() {
  // put your main code here, to run repeatedly:

}

https://github.com/esp8266/Arduino/issues/1126
にemptyファイルで生成時にエラーがでる報告があり、この症状に近い状況(!fエラー)が何回か起こっていたように思うが、何かの拍子でエラーがでなくなった。

fd.close()をしないままfd.open()をしてしまっていたのだろうか。詳細は分からない。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5