B4R Library rRadioHead - RF95 / Dragino Lora shield

Discussion in 'B4R Libraries' started by Erel, Dec 3, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    This is a wrapper for RadioHead library. Currently only RF95 is exposed.
    RadioHead documentation: http://www.airspayce.com/mikem/arduino/RadioHead/classRH__RF95.html#details

    "Driver to send and receive unaddressed, unreliable datagrams via a LoRa capable radio transceiver."

    Installation steps:
    1. Download the attached library and copy to the additional libraries folder.
    2. Download RadioHead and copy it to Arduino libraries folder (by default it is Documents\Arduino\libraries).

    [​IMG]

    Usage:

    1. Initialize RF95 and make sure that it returns True.
    2. Set the frequency.
    2. Send messages with RF95.Send.
    3. Handle the DataAvailable event.

    Max message length is 251 bytes.

    Example:

    Program A:
    Code:
    Sub Process_Globals
       
    Public Serial1 As Serial
       
    Private rf95 As RF95
       
    Private ser As B4RSerializator
    End Sub

    Private Sub AppStart
       Serial1.Initialize(
    115200)
       
    Log("AppStart")
       
    If rf95.Initialize("rf95_DataAvailable") = False Then
         
    Log("Failed to init!!!")
         
    Return
       
    End If
       rf95.Frequency = 
    868.1
    End Sub

    Sub rf95_DataAvailable (Data() As Byte)
       
    Dim objects(5As Object
       
    Dim res() As Object = ser.ConvertBytesToArray(Data, objects)
       
    If res.Length > 0 Then
         
    Log("Message received from: ", res(0))
         
    Dim time As ULong = res(1)
         
    Log("Message time: ", time)
         rf95.Send(ser.ConvertArrayToBytes(
    Array("Mega - Thank you!", Millis)))
       
    End If
    End Sub
    Program B:
    Code:
    Sub Process_Globals
       
    Public Serial1 As Serial
       
    Private rf95 As RF95
       
    Private timer1 As Timer
       
    Private ser As B4RSerializator
    End Sub

    Private Sub AppStart
       Serial1.Initialize(
    115200)
       
    Log("AppStart")
       
    If rf95.Initialize("rf95_DataAvailable") = False Then
         
    Log("Failed to init!!!")
         
    Return
       
    End If
       rf95.Frequency = 
    868.1
       timer1.Initialize(
    "timer1_Tick"1000)
       timer1.Enabled = 
    True
    End Sub

    Sub Timer1_Tick
       
    Dim b() As Byte = ser.ConvertArrayToBytes(Array("Arduino Uno", Millis))
       
    If rf95.Send(b) = False Then
         
    Log("Failed to send message")
       
    End If
    End Sub

    Sub rf95_DataAvailable (Data() As Byte)
       
    Dim objects(5As Object
       
    Dim res() As Object = ser.ConvertBytesToArray(Data, objects)
       
    If res.Length > 0 Then
         
    Log("Message received from: ", res(0))
         
    Dim time As ULong = res(1)
         
    Log("Message time: ", time)
       
    End If
    End Sub
    Examples depend on rRadioHead and rRandomAccessFile libraries.
     

    Attached Files:

  2. janderkan

    janderkan Active Member Licensed User

    Erel likes this.
  3. janderkan

    janderkan Active Member Licensed User

    I create a new project.
    I include rRadiohead library, but do not use it.
    It compiles fine on a UNO or a Mega.
    When I select a Wemos R1 D1 Mini I get this error.

    Code:
    C:\2Work\1C\B4R\RADIOH~1\Objects\bin\sketch\rRadioHead.cpp: In member function 'bool B4R::B4RRF95::Send(B4R::Array*)':
    rRadioHead.cpp:22: error: invalid conversion from 'void*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
       return rf95->send(Data->data, Data->length);
                                                 ^
    In file included from C:\2Work\1C\B4R\RADIOH~1\Objects\bin\sketch\rRadioHead.h:5:0,
                     from C:\2Work\1C\B4R\RADIOH~
    1\Objects\bin\sketch\B4RDefines.h:25,
                     from C:\2Work\1C\B4R\RADIOH~
    1\Objects\bin\sketch\rRadioHead.cpp:1:
    C:\Program Files (x86)\Arduino\libraries\RadioHead/RH_RF95.h:
    672:21: error:   initializing argument 1 of 'virtual bool RH_RF95::send(const uint8_t*, uint8_t)' [-fpermissive]
         virtual bool    send(const uint8_t* data, uint8_t len);
                         ^
    exit status 1
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The error is inside the RadioHead library. It looks like it is not compatible with ESP8266.
     
    janderkan likes this.
  5. janderkan

    janderkan Active Member Licensed User

    I can use the RH_RF95 library on the same Wemos, if I use Arduino !
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Try to change line 22 in rRadioHead.cpp to:
    Code:
    return rf95->send((Byte*)Data->data, Data->length);
    With this fix I'm still getting an error:
    C:\Users\H\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:44:1: error: when initialized here [-Werror=reorder]
     
    janderkan likes this.
  7. janderkan

    janderkan Active Member Licensed User

    Now I can compile both RF95 and ASK on the Wemos. Need a little more time to know if it is also working :)
    I find i very hard to C.

    UPDATE: It works.
     
    Last edited: Aug 5, 2018
    Peter Simpson likes this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    You didn't get the error I saw?
     
  9. janderkan

    janderkan Active Member Licensed User

    NO, Compiles and works. No error.
    Radiohead v1.85
    Arduino v1.8.1
    B4R v2.51

    I will send you my rRadioHead before I release it.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    You need to change line 57 in rRF95.cpp to:
    Code:
    return rf95->sleep();
    I'm still getting the error I previously posted. Might be related to a different version of Arduino IDE which affects the c++ compiler settings.

    Go ahead and release your library.
     
    janderkan likes this.
  11. janderkan

    janderkan Active Member Licensed User

    Here are my additions to rRadioHead library.
    Most of the functions are exposed and constants added to make it easier to use.
    Radiohead protocol prefixes the datagram with 4 bytes to make it possible to send addressable, reliable packets.
    Added properties to access these 4 bytes.

    Exposed the ASK class that makes it possible to send and receive data the same way as the RF95 class.
    Using very cheap ASK modules instead of the Lora modules.
    433-chip.jpg
     

    Attached Files:

    inakigarm and Erel like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice