B4R Question arduino-LoRa

miker2069

Active Member
Licensed User
Longtime User
Well you could try modifying the existing B4R Lora library to add the functionality you like (like exposing the pins you indicated).

I had to do something similar with the nrf24l01 library - the B4R nrf24l01 library only exposed a few of the functions and I needed more. My B4R library skills are pretty weak (actually non-existent) so I wrapped everything in inline C and it works great - for me inline C is way easier and there are a lot of examples on the forum.

I would recommend creating an inline C function called "init" (or something like that) where you do all the setup you would normally do in an Arduino Sketch setup() function.
 
Upvote 0

candide

Active Member
Licensed User
a wrapper for LoRa can be something like zip file attached, please to test it if it can help you and we will see...

B4R file with LoRa can be something like that:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 500
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public lora As LoRaClass
    Public csPin As Int = 7
    Public resetPin As Int = 6
    Public irqPin As Int = 1
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    lora.Initialize
    lora.setPins(csPin, resetPin, irqPin)
    lora.begin("DataAvailable",915E6)
    lora.PreambleLength = 10

End Sub

private Sub DataAvailable  'if parsePacket() <> 0
    Dim recipient As Int  = lora.read()
    Dim senders As Byte = lora.read()            '// Sender address
    Dim incomingMsgId As Byte = lora.read()     '// incoming msg ID
    Dim incomingLength As Byte = lora.read()    '// incoming msg length

    Dim incoming() As Byte = "";

    Do While  (lora.available() <> 0) 
       incoming = JoinBytes(Array(lora.read(),Array(incoming)))
    Loop
  
End Sub
 

Attachments

  • rLoRa.zip
    8.3 KB · Views: 147
Upvote 0

sot bel

Member
Thank you Candide.

I tested it . It starts good receiving...
recipient,
senders,
incomingMsgId,
incomingLength,

but code crashes in this line..

incoming = JoinBytes(Array(lora.read(),Array(incoming)))
 
Upvote 0

candide

Active Member
Licensed User
to use joinBytes was not a good idea to test lora.read.

can you just make a Log(lora.read) in the reception loop? to check if the crask is due to lora.read or joinBytes
 
Upvote 0

sot bel

Member
lora.read is ok.... the problem is in joinBytes

I send a string from an arduino module ---> ASE7^5060303071^0^0.0^0^0^1^0^0^0^0^0.0^0^-10^0^0

I can receive string's separated bytes as integer numbers but i want it as string again
 
Upvote 0

sot bel

Member
Code is running on an ESP32



private Sub DataAvailable 'if parsePacket() <> 0
Dim recipient As Int = lora.read()
Log("recipient = ",recipient)
Dim senders As Byte = lora.read() '// Sender address
Log("senders = ",senders)
Dim incomingMsgId As Byte = lora.read() '// incoming msg ID
Log("incomingMsgId = ",incomingMsgId)
Dim incomingLength As Byte = lora.read() '// incoming msg length
Log("incomingLength = ",incomingLength)
Dim incoming() As Byte

Do While (lora.available() <> 0)

Log("lora.read = ",lora.read())
incoming = JoinBytes(Array(lora.read(),Array(incoming)))

Loop
Log(incoming)

End Sub



B4R Logs



********************* PROGRAM STARTING ****************
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:2

load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac


AppStart
recipient = 187
senders = 255
incomingMsgId = 0
incomingLength = 47
lora.read = 65
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d0ff5 PS : 0x00060930 A0 : 0x800d17a0 A1 : 0x3ffb1ea0
A2 : 0x3ffb81cc A3 : 0x3ffb1f00 A4 : 0x3ffc00f4 A5 : 0x00000000
A6 : 0x3ffc00f8 A7 : 0x00000053 A8 : 0x00000008 A9 : 0x00000000
A10 : 0x3ffb81d4 A11 : 0x00000018 A12 : 0x00000001 A13 : 0x00000008
A14 : 0x00000000 A15 : 0xfffffff8 SAR : 0x0000001b EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000057 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
Backtrace: 0x400d0ff5:0x3ffb1ea0 0x400d179d:0x3ffb1ec0 0x400d1892:0x3ffb1f30 0x400d165e:0x3ffb1f50 0x400d16a7:0x3ffb1f70 0x400d191e:0x3ffb1f90 0x400d2b01:0x3ffb1fb0 0x40088215:0x3ffb1fd0
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
AppStart




when i comment this line

'incoming = JoinBytes(Array(lora.read(),Array(incoming)))




ESP32 logs


********************* PROGRAM STARTING ****************
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
AppStart
recipient = 187
senders = 255
incomingMsgId = 0
incomingLength = 47
lora.read = 65
lora.read = 83
lora.read = 69
lora.read = 55
lora.read = 94
lora.read = 53
lora.read = 48
lora.read = 54
lora.read = 48
lora.read = 51
lora.read = 48
lora.read = 51
lora.read = 48
lora.read = 55
lora.read = 49
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 46
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 49
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 46
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
lora.read = 94
lora.read = 48
 
Last edited:
Upvote 0

candide

Active Member
Licensed User
incoming = JoinBytes(Array(lora.read(),Array(incoming)))

this line have bug a because lora.read is a byte and not an array of byte
something like that should be better : incoming = JoinBytes(Array(Array As Byte(lora.read()) ,Array(incoming)))

other way, to use this function :
Private Sub chr(b As Byte) As Byte()
Return Array As Byte(b)
End Sub

more information on similar question on this thread :
 
Upvote 0

sot bel

Member
After many tries
This is the corect

incoming = JoinBytes(Array(incoming,Array As Byte(lora.read())))


now the result is...

incoming = ASE7^5060303071^0^0.0^0^0^1^0^0^0^0^0.0^0^0^0^0
 
Upvote 0
Top