If I send one transmission right after another, I get an error.
I need to wait until the LoRa module returns "+OK" before I can send again.
How is the best way to do this?
Thank you in advance for all the help!
My code is below
I need to wait until the LoRa module returns "+OK" before I can send again.
How is the best way to do this?
Thank you in advance for all the help!
My code is below
B4R Code:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src
Sub Process_Globals
Public Serial1 As Serial
'TXD1/RXD1 Serial for RYLR998
Private SerialNative1 As Stream 'https://www.b4x.com/android/forum/threads/additional-hardware-serial-ports.67150/
Private eol() As Byte = Array As Byte(13, 10)
Private stream1 As AsyncStreams
Dim StartTime As ULong
Dim DoneTime As ULong
Dim TXTime As ULong
Dim TXOK As Boolean = True
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Delay(2000)
'Serial for RYLR998 connected to Hardware Serial Port 1.
RunNative("SerialNative1", Null)
stream1.Initialize(SerialNative1, "RYLR998_NewData", Null)
LoRaSend("Ready for Liftoff!", " Buckle up!")
TXOK = False
'Here I need to wait until OK is received before sending again.
LoRaSend("Ready for Liftoff!2", " Buckle up!")
End Sub
#if C
void SerialNative1(B4R::Object* unused) {
::Serial1.begin(115200); //<--You can change the baud rate
b4r_main::_serialnative1->wrappedStream = &::Serial1;
}
#end if
Private Sub LoRaSend(SendData1 As String, SendData2 As String)
'Send data via RYLR998 connected to Hardware Serial Port 1.
Dim SendData As String = JoinStrings(Array As String(SendData1, SendData2))
'Log("Send Data = ", SendData)
Dim ReceiverAddress As Byte = 1 '0 to 65535. Must match reciever's address.
Dim Buffer() As Byte = JoinStrings(Array As String("AT+SEND=",ReceiverAddress,",",SendData.Length,",",SendData))
StartTime = Millis
Log("SendData = ",SendData)
Log("StartTime = ", StartTime)
SerialNative1.WriteBytes(Buffer, 0, Buffer.Length)
SerialNative1.WriteBytes(eol, 0, eol.Length)
End Sub
Sub RYLR998_NewData (Buffer() As Byte)
DoneTime = Millis
'Log("Received from RYLR998: '",Buffer,"'")
Dim bc As ByteConverter
Log("Substring = ", bc.SubString2(Buffer,1,3))
'Substring will = "OK" when transmission is done.
'If Substring is OK, then it is OK to send something else.
TXTime = DoneTime - StartTime
Log("TX Time = ", TXTime)
Log(" ")
TXOK = True
End Sub