Hi,
I would like to ask is it possible if in 1 seconds, I want to write 500 records into Little FS?
I'm using WeMos Mini D1 R2 device
Below is my coding and I able to write 25 records only in 3 secords
Is there any way to write 500 Records in 1 seconds
Thank for helping
I would like to ask is it possible if in 1 seconds, I want to write 500 records into Little FS?
I'm using WeMos Mini D1 R2 device
Below is my coding and I able to write 25 records only in 3 secords
B4X:
Sub Process_Globals
Dim start_status As Int = 0
Dim count As Long = 0
Private t1 As Timer
End Sub
Private Sub AppStart
Log("Initializing Filesystem...")
If(lfs.Initialize())=False Then
Log("Formatting Filesystem. This may take some time")
lfs.Format
If(lfs.Initialize())=True Then
Log("Formatting succesful...")
Else
Log("Error formatting Filesystem...")
End If
End If
Log("Total size: ", NumberFormat(lfs.TotalSize / 1024, 0, 0), " KB")
Log("Used size: ", NumberFormat(lfs.UsedSize / 1024, 0, 0), " KB")
data_default
t1.Initialize("t1_Tick",3000)
t1.Enabled=False
AddLooper("Looper1")
End Sub
Sub data_default
If lfs.Exists("/testpost") = False Then
Dim Buffer() As Byte
If lfs.OpenReadWrite("/testpost") = True Then
lfs.Position = lfs.CurrentFile.Size
Buffer = bc.StringToBytes(0)
lfs.Stream.WriteBytes(Buffer,0,Buffer.Length)
lfs.Stream.Flush
lfs.Close
End If
End If
End Sub
Sub t1_Tick
start_status=2
t1.Enabled=False
Dim f1 As String = ReadData("/testpost")
Log("f1 ", f1)
Dim file1 As String = ReadData("/test.txt")
Log("file1 ", file1)
End Sub
Sub Looper1
If start_status = 0 Then
If lfs.Exists("/test.txt") Then
lfs.Remove("/test.txt")
Log("test.txt Deleted")
End If
start_status=1
lfs.OpenReadWrite("/test.txt")
t1.Enabled=True
else if start_status = 1 Then
count = count + 1
SaveData1("/test.txt",count)
else if start_status = 2 Then
start_status = 99
ListFiles
End If
End Sub
Sub ReadData(data As String) As String
Dim result As String = ""
If lfs.OpenRead(data) = True Then
Dim NByte As Int=lfs.Stream.BytesAvailable
Dim Buffer(NByte) As Byte
lfs.Stream.ReadBytes(Buffer, 0, NByte)
lfs.Stream.Flush
result = bc.StringFromBytes(Buffer)
lfs.Close
End If
Return result
End Sub
private Sub SaveData1(filename As String,data As String)
Dim s As String
If data.Length = 1 Then
s = JoinStrings(Array As String("00",data, CRLF))
Else If data.Length = 2 Then
s = JoinStrings(Array As String("0",data, CRLF))
Else
s = JoinStrings(Array As String(data, CRLF))
End If
Dim Buffer() As Byte
Dim count1 As ULong
If lfs.OpenReadWrite("/testpost") = True Then
count1=ReadData("/testpost")
lfs.Close
End If
If lfs.OpenReadWrite(filename) = True Then
lfs.Position = count1
Buffer = bc.StringToBytes(s)
lfs.Stream.WriteBytes(Buffer,0,Buffer.Length)
lfs.Stream.Flush
lfs.Close
End If
count1=count1+5
Dim lg As ULong =1800000
If count1<=lg Then
SaveData2(count1)
Else
count1=0
SaveData2(0)
End If
End Sub
private Sub SaveData2(count1 As ULong)
Dim Buffer() As Byte
lfs.Remove("/testpost")
If lfs.OpenReadWrite("/testpost") = True Then
lfs.Position = lfs.CurrentFile.Size
Buffer = bc.StringToBytes(count1)
lfs.Stream.WriteBytes(Buffer,0,Buffer.Length)
lfs.Stream.Flush
lfs.Close
End If
End Sub
Is there any way to write 500 Records in 1 seconds
Thank for helping
Last edited: