Hi,
I'm new to the platform so I apologize upfront in case this turns out to be a stupid question.
I have an ESP01 (ESP8266) module and I want to store some data that will survive restarts of the ESP01. If I understood well, one of the options to achieve this is to use the ESP8266 file system implemented by the rESP8266FileSystem (V1.0) library. I used code as shown. The code doesnt work and I dont see any errors at runtime either.
The logging indicates there are 10 bytes written which is as I expected, but there are 0 bytes (no data) read and the file position remains 0
Furthermore the ListFiles Sub doesnt list any files at all, although the ReadFile Sub can find the file. I also tried to format the file system first (code removed), but that doesnt help either.
What am I doing wrong?
I'm new to the platform so I apologize upfront in case this turns out to be a stupid question.
I have an ESP01 (ESP8266) module and I want to store some data that will survive restarts of the ESP01. If I understood well, one of the options to achieve this is to use the ESP8266 file system implemented by the rESP8266FileSystem (V1.0) library. I used code as shown. The code doesnt work and I dont see any errors at runtime either.
The logging indicates there are 10 bytes written which is as I expected, but there are 0 bytes (no data) read and the file position remains 0
Furthermore the ListFiles Sub doesnt list any files at all, although the ReadFile Sub can find the file. I also tried to format the file system first (code removed), but that doesnt help either.
What am I doing wrong?
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 1000
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private fs As ESP8266FileSystem
Private myFile As String = "myFiles/file1"
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Delay(1000)
Log("AppStart")
Start
End Sub
Sub Start
If(fs.initialize) Then
Log(" file system successfully initialized")
Else
Log("could not initialize filesystem")
End If
WriteFile
Readfile
ListFiles
End Sub
Sub WriteFile
If (fs.OpenReadWrite(myFile)) Then
Log("file successfyully openend for write processing")
Private buffer(10) As Byte ="1234567890".GetBytes
Log("Bytes written: ", fs.Stream.WriteBytes(buffer,0,buffer.Length))
Log("file system total size ", fs.TotalSize)
Log("file system used size ", fs.UsedSize)
Log("file size ", fs.CurrentFile.size)
fs.Close
End If
End Sub
Sub Readfile
If (fs.OpenRead(myFile)) Then
Log("file successfyully openend for read processing")
Log("file name ", fs.CurrentFile.Name)
Log("file size ", fs.CurrentFile.size)
fs.Position=0
Private buffer(10) As Byte
Log ("number of bytes read: ", fs.Stream.ReadBytes(buffer,0,buffer.Length))
Log("position after reading file: ", fs.Position)
Private conv As ByteConverter
Log("data read: ", conv.StringFromBytes(buffer))
fs.Close
Else
Log("cannot open file for read: ", myFile)
End If
End Sub
Sub ListFiles
For Each f As File In fs.ListFiles("/")
Log("Name: ", f.Name, ", Size: ", f.Size)
Next
End Sub