B4R Question FileTransfer in the Adruino

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

vahiddehghani

New Member
Thank you Erel

B4X:
Sub Astream_NewData (Buffer() As Byte)
    
    'Log("Command: ", bc.HexFromBytes(Buffer))
    
    If receivingMode Then
        WriteIncomingData(Buffer)
        Return
    Else
        Select Buffer(0)
            Case TASK_LISTFILES
                ListFiles1
            Case TASK_SENDFILE
                SendFile(Buffer)
            Case TASK_RECEIVEFILE
                set("SD")
                ReceiveFileName(Buffer)
                set("EN")
                Return
        End Select
    End If
    Delay(100)
    socket.Close
    set("RFID")


End Sub

Sub Astream_Error
    Log("Closed")
    If receivingMode Then
        receivingMode = False
        set("SD")
        Log("Stored file size: ", sd.CurrentFile.Size)
        sd.Close
        set("RFID")
    End If
    ethServer.Listen
End Sub

Sub ReceiveFileName (Buffer() As Byte)
    Dim fileNameLength As Byte = Buffer(1)
    Dim fileName() As Byte = bc.SubString2(Buffer, 2, 2 + fileNameLength)
    Log("Receiving: ", fileName)
    receivingMode = True
    sd.OpenReadWrite(bc.StringFromBytes(fileName))
    WriteIncomingData(bc.SubString(Buffer, 2 + fileNameLength))
End Sub

Sub WriteIncomingData(Buffer() As Byte)
    sd.Stream.WriteBytes(Buffer, 0, Buffer.Length)
End Sub


I changed the code to connect the network
But it only receives 1 byte of file information
For example, the 1.txt file, which is 512KB in size, gets 1Kb in size after it's received
 
Upvote 0
Top