0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

wemosでspiffs その2

Posted at

概要

wemos d1 r1でspiffsやってみた。
バイナリー書いてみた。

サンプルコード

# include <Arduino.h>
# include <FS.h>

uint8_t buf[100];

void setup() {
	char i;
	Serial.begin(115200);
	for (i = 0; i < 100; i++)
	{
		buf[i] = i;
	}
	bool res = SPIFFS.begin();
	if (!res)
	{
		Serial.printf("SPIFFS error \n");
		while (true) {};
	}
	Dir dir = SPIFFS.openDir("/");
	while (dir.next())
	{
		String fn,
			fs;
		fn = dir.fileName();
		fn.remove(0, 1);
		fs = String(dir.fileSize());
		Serial.printf("%s\t%s\n", fn.c_str(), fs.c_str());
	}
	String s = "/ss.ore";
	File fd = SPIFFS.open(s, "w");
	if (!fd)
	{
		Serial.println("open error1");
		return;
	}
	fd.write(buf, 100);
	fd.close();
	Serial.println("ok0");
	File fileToRead = SPIFFS.open(s, "r");
	if (!fileToRead)
	{
		Serial.println("Failed to open file for reading");
		return;
	}
	fileToRead.readBytes((char *) buf, 100);
	fileToRead.close();
	Serial.println("ok1");
	for (i = 0; i < 100; i++)
	{
		Serial.println(buf[i], HEX);
	}
}
void loop() {
	delay(10);
}



以上。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?