Problems with SPIFFS.h / FS.h / close-function

Hello,

I get an every time an error when I include the SPIFFS.h and FS.h. When I look in at the errors I think there is a problem with the close-function which is used for closing the file-stream.

here is the error log:

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 32 > Espressif ESP32 Dev Module
SYSTEM: ESP32 240MHz 320KB RAM (4MB Flash)
DEBUG: CURRENT(esp-prog) EXTERNAL(esp-prog, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)

Collected 24 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPIFFS> 1.0
|   |-- <FS> 1.0
|-- <SPI> 1.0
|-- <Preferences> 1.0
|-- <Ticker> 1.1
|-- <FS> 1.0
Compiling .pioenvs/esp32dev/src/Menu.cpp.o
Compiling .pioenvs/esp32dev/src/main.cpp.o
In file included from /Users/daniel/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/stdio.h:29:0,
from /Users/daniel/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:27,
from /Users/daniel/.platformio/packages/framework-arduinoespressif32/libraries/Preferences/src/Preferences.h:17,
from src/Menu.h:17,
from src/Menu.cpp:12:
/Users/daniel/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/sys/unistd.h:30:9: error: 'int close(int)' redeclared as different kind of symbol
int     _EXFUN(close, (int __fildes ));
^
In file included from src/Menu.h:20:0,
from src/Menu.cpp:12:
src/Valve/Valve.h:13:31: note: previous declaration 'ValveState close'
enum ValveState { open = 'O', close = 'C', nothing = 'N' };
^
In file included from /Users/daniel/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/stdio.h:29:0,
from /Users/daniel/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32/esp_timer.h:43,
from /Users/daniel/.platformio/packages/framework-arduinoespressif32/libraries/Ticker/src/Ticker.h:29,
from src/main.cpp:11:
/Users/daniel/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/sys/unistd.h:30:9: error: 'int close(int)' redeclared as different kind of symbol
int     _EXFUN(close, (int __fildes ));
^
In file included from src/Menu.h:20:0,
from src/main.cpp:14:
src/Valve/Valve.h:13:31: note: previous declaration 'ValveState close'
enum ValveState { open = 'O', close = 'C', nothing = 'N' };
^
src/Menu.cpp: In member function 'void DisplayMenu::switchMenuVerticalH(bool)':
src/Menu.cpp:134:8: warning: unused variable 'dummy' [-Wunused-variable]
int dummy = this->u8iSettingValveState;
^
*** [.pioenvs/esp32dev/src/Menu.cpp.o] Error 1
*** [.pioenvs/esp32dev/src/main.cpp.o] Error 1
========================== [ERROR] Took 1.80 seconds ==========================

And here the code in which I am using the SPIFFS functionality:

includes form menu.h

//************************************************************************
//include of needed library's
//************************************************************************
//#include "Arduino.h"
#include "Preferences.h"
#include "Programs/Programs.h"
#include "Display/PCD8544.h"
#include "Valve/Valve.h"
#include "Temp/Adafruit_MAX31865.h"

#include "FS.h"
#include "SPIFFS.h"

and here the function in menu.cpp in this I am using it:

//----------------------------------------------
void                DisplayMenu::loadOwnPrograms  ( )
{
		uint8_t u8iBuffer[sizeof(stuPROGRAM)];
		uint8_t *u8iDummy;

		if ( !SPIFFS.begin() )
			return;
		File file = SPIFFS.open( "/OwnPro.dat", FILE_READ );

		if ( !file )
			return;

		for ( int i = 0; i < 5; i++ )
		{
			if ( !file.read( u8iBuffer, sizeof( stuPROGRAM ) ) )
			{
				return;
			}
			u8iDummy = ( uint8_t * ) &OwnPrograms[i];
			for ( int j = 0; j < sizeof(stuPROGRAM); j++ )
				*u8iDummy++ = u8iBuffer[j];
		}
		file.close();
		SPIFFS.end();
		return;

}

I don’t know where my mistake is…

Greetings Daniel

This comes from your own code, by calling the ValveState values open and close, you are overwriting the C-standard library functions open() and close() to your enum values. Rename your enum values (e.g., prefix them, or use the enum class in C++)

1 Like

Thank you very much…No it works…

Greetings Daniel

Sorry…NOW it works…