Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Porting MySensors to work with the RadioHead library

Porting MySensors to work with the RadioHead library

Scheduled Pinned Locked Moved Development
portingradiohead
288 Posts 24 Posters 187.4k Views 12 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K kolaf

    The trouble with initialising the radio separately by the user is that it increases the complexity, which I think is one of @HEK's major points with the library. It definitely looks like the easiest way to support multiple radios, but the question is, is it good enough?

    YveauxY Offline
    YveauxY Offline
    Yveaux
    Mod
    wrote on last edited by
    #82

    @kolaf I understand @hek 's reservations.
    Maybe we can add a function to MySensors that returns a static instance to the radio, all configured to use with MySensors.

    #include <MySensor.h>  
    MySensor gw;
    
    void setup() 
    {
      // Start MySensors and pass it the radio to use. Mysensors manages the instance
      // and configures the radio with defaults for us.
      // 'power users' can instantiate their own radio and configure it to their liking
      gw.begin( gw.createRadio() );
    }
    

    How 'bout that?

    http://yveaux.blogspot.nl

    hekH K 2 Replies Last reply
    0
    • YveauxY Yveaux

      @kolaf I understand @hek 's reservations.
      Maybe we can add a function to MySensors that returns a static instance to the radio, all configured to use with MySensors.

      #include <MySensor.h>  
      MySensor gw;
      
      void setup() 
      {
        // Start MySensors and pass it the radio to use. Mysensors manages the instance
        // and configures the radio with defaults for us.
        // 'power users' can instantiate their own radio and configure it to their liking
        gw.begin( gw.createRadio() );
      }
      

      How 'bout that?

      hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #83

      @Yveaux @kolaf

      Now we're talking!

      Really appreciate you're effort on RadioHead while still keeping it simple for the end-user.

      I'm finalizing the documentation for 1.4 so we can release it and continue the work on RadioHead and the new protocol changes. As @Damme said somewhere, this might be enough for a 2.0 version :).

      1 Reply Last reply
      0
      • YveauxY Yveaux

        @kolaf I understand @hek 's reservations.
        Maybe we can add a function to MySensors that returns a static instance to the radio, all configured to use with MySensors.

        #include <MySensor.h>  
        MySensor gw;
        
        void setup() 
        {
          // Start MySensors and pass it the radio to use. Mysensors manages the instance
          // and configures the radio with defaults for us.
          // 'power users' can instantiate their own radio and configure it to their liking
          gw.begin( gw.createRadio() );
        }
        

        How 'bout that?

        K Offline
        K Offline
        kolaf
        Hero Member
        wrote on last edited by
        #84

        @Yveaux said:

        How 'bout that?

        That makes sense. I will need some help to build the default radio configuration that you use, and I can start redoing the initialisation stuff.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kolaf
          Hero Member
          wrote on last edited by
          #85

          I have made some progress on the proposed initialisation routines and I am at the point where something works. The current initialisation for my sensor looks like this:

          #include <MySensor.h>
          #include <RH_RF69.h>
          #include <SPI.h>
          
          RH_RF69 driver;
          
          MySensor gw;
          void setup()  
          {  
            
            if(gw.setRadio(&driver)) {
          	driver.setFrequency(868);
          	driver.setTxPower(14);
          	gw.begin();
            }
          }
          

          I stumbled upon a few snags on the way. For instance, when you initialise the manager (after giving it the driver) it sets up a bunch of defaults. This means that we have to override these defaults after the manager is initialised. This is why I split this out in a separate function setRadio. This function initialises the manager and returns true if this is successful. You may then set up your optional parameters and call begin.

          A great benefit of having the radio include in the source file instead of in the library is that we now do not have to distribute it inside the MySensors library. We can now use a regular Radiohead installation in the Arduino environment. I have pushed this to my repository, let me know what you think.

          https://github.com/kolaf/Arduino/tree/radiohead_port

          YveauxY 1 Reply Last reply
          0
          • K Offline
            K Offline
            kolaf
            Hero Member
            wrote on last edited by
            #86

            The next challenge is sleeping. The different drivers sleep using different function calls.

            1 Reply Last reply
            0
            • K kolaf

              I have made some progress on the proposed initialisation routines and I am at the point where something works. The current initialisation for my sensor looks like this:

              #include <MySensor.h>
              #include <RH_RF69.h>
              #include <SPI.h>
              
              RH_RF69 driver;
              
              MySensor gw;
              void setup()  
              {  
                
                if(gw.setRadio(&driver)) {
              	driver.setFrequency(868);
              	driver.setTxPower(14);
              	gw.begin();
                }
              }
              

              I stumbled upon a few snags on the way. For instance, when you initialise the manager (after giving it the driver) it sets up a bunch of defaults. This means that we have to override these defaults after the manager is initialised. This is why I split this out in a separate function setRadio. This function initialises the manager and returns true if this is successful. You may then set up your optional parameters and call begin.

              A great benefit of having the radio include in the source file instead of in the library is that we now do not have to distribute it inside the MySensors library. We can now use a regular Radiohead installation in the Arduino environment. I have pushed this to my repository, let me know what you think.

              https://github.com/kolaf/Arduino/tree/radiohead_port

              YveauxY Offline
              YveauxY Offline
              Yveaux
              Mod
              wrote on last edited by Yveaux
              #87

              @kolaf said:

              For instance, when you initialise the manager (after giving it the driver) it sets up a bunch of defaults.

              Yes, I see it calls init() from the driver, which sucks...
              I'll guess you want gw.setradio to initialize the manager then (which in turn initializes the driver)? This way you'll be able to modify the driver's parameters before MySensors starts. Not a very elegant way... (but I also don't have a better solution at the moment...)

              http://yveaux.blogspot.nl

              K 1 Reply Last reply
              0
              • YveauxY Yveaux

                @kolaf said:

                For instance, when you initialise the manager (after giving it the driver) it sets up a bunch of defaults.

                Yes, I see it calls init() from the driver, which sucks...
                I'll guess you want gw.setradio to initialize the manager then (which in turn initializes the driver)? This way you'll be able to modify the driver's parameters before MySensors starts. Not a very elegant way... (but I also don't have a better solution at the moment...)

                K Offline
                K Offline
                kolaf
                Hero Member
                wrote on last edited by
                #88

                @Yveaux Exactly.

                1 Reply Last reply
                0
                • YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by
                  #89

                  @kolaf Have you checked initialization of the managers for any radio communication taking place? If it does, your solution will not work as it will be executed using the default radio parameters...

                  http://yveaux.blogspot.nl

                  K 1 Reply Last reply
                  0
                  • YveauxY Yveaux

                    @kolaf Have you checked initialization of the managers for any radio communication taking place? If it does, your solution will not work as it will be executed using the default radio parameters...

                    K Offline
                    K Offline
                    kolaf
                    Hero Member
                    wrote on last edited by
                    #90

                    @Yveaux I don't think there is any radio communication, it just initialises the radio chip and confirms that it is able to communicate with it. Otherwise you would have had real problems with trying to start every radio at the same time :-)

                    1 Reply Last reply
                    0
                    • YveauxY Yveaux

                      I just built my first nRF24L01+ setup using the RadioHead library running the nrf24_reliable_datagram_client and nrf24_reliable_datagram_server sketches on two Uno's.

                      Works like a charm, after I disconnected the interrupt line to the nRF24.
                      Don't know why yet (possibly an interrupt handler is 'secretly' installed by the library), but it took me some time to figure out...

                      Also requires the driver to be constructed as RH_NRF24 driver(9, 10) when using the MySensors connection-scheme.

                      YveauxY Offline
                      YveauxY Offline
                      Yveaux
                      Mod
                      wrote on last edited by
                      #91

                      @Yveaux said:

                      Works like a charm, after I disconnected the interrupt line to the nRF24.

                      I went through the RadioHead code, looking for enabled INT0 interrupts, interrupts handlers etc. in nRF24 code.
                      Found none, so tested again today, with the interrupt line connected.

                      Now it also works with interrupt connected...

                      Don't know what went wrong before.

                      http://yveaux.blogspot.nl

                      K 1 Reply Last reply
                      0
                      • YveauxY Yveaux

                        @Yveaux said:

                        Works like a charm, after I disconnected the interrupt line to the nRF24.

                        I went through the RadioHead code, looking for enabled INT0 interrupts, interrupts handlers etc. in nRF24 code.
                        Found none, so tested again today, with the interrupt line connected.

                        Now it also works with interrupt connected...

                        Don't know what went wrong before.

                        K Offline
                        K Offline
                        kolaf
                        Hero Member
                        wrote on last edited by
                        #92

                        @Yveaux Good to hear that it is working out for you. I'm very curious to see whether you can get my version of the library working with your radio.

                        I have posted on the Radiohead group to see whether they can implement a generic sleep function in the driver or in the manager. This would make it much easier for us to put everything to sleep when required. Short of that the only reasonable solution I can see to fix this is to create a sleep function in the sensor source code and pass this as a parameter to the library. Alternatively we can build a different sleep functions in the library, but I guess this will cause the same problems as you talked about earlier with bringing in a lot of code we do not need.

                        YveauxY hekH 3 Replies Last reply
                        0
                        • K kolaf

                          @Yveaux Good to hear that it is working out for you. I'm very curious to see whether you can get my version of the library working with your radio.

                          I have posted on the Radiohead group to see whether they can implement a generic sleep function in the driver or in the manager. This would make it much easier for us to put everything to sleep when required. Short of that the only reasonable solution I can see to fix this is to create a sleep function in the sensor source code and pass this as a parameter to the library. Alternatively we can build a different sleep functions in the library, but I guess this will cause the same problems as you talked about earlier with bringing in a lot of code we do not need.

                          YveauxY Offline
                          YveauxY Offline
                          Yveaux
                          Mod
                          wrote on last edited by
                          #93

                          @kolaf said:

                          I have posted on the Radiohead group to see whether they can implement a generic sleep function in the driver or in the manager

                          Ah great! Let's see how flexible they are ;-)

                          Btw. I'm not totally dismissive of the idea of making small changes to the RadioHead library when it makes our life easier to get a clean interface for MySensors users. Indeed, we have to sync changes (which are almost on a daily basis right now, but that will settle over time) but when the changes to the original library are relatively small this won't be too hard.

                          Anyway, let's not give up yet and see if we can use the vanilla library.

                          http://yveaux.blogspot.nl

                          1 Reply Last reply
                          0
                          • YveauxY Offline
                            YveauxY Offline
                            Yveaux
                            Mod
                            wrote on last edited by
                            #94

                            I created a github repo containing the RadioHead sources, including change history. The code is commit using a script, so future updates can easily be added.

                            IMHO having the RadioHead library sourcecode under version control is a requrement for inclusion in MySensors and if we ever decide to make small changes to the library we can now easily fork from the original sourcecode.

                            Get it at https://github.com/Yveaux/RadioHead

                            http://yveaux.blogspot.nl

                            1 Reply Last reply
                            0
                            • K kolaf

                              @Yveaux Good to hear that it is working out for you. I'm very curious to see whether you can get my version of the library working with your radio.

                              I have posted on the Radiohead group to see whether they can implement a generic sleep function in the driver or in the manager. This would make it much easier for us to put everything to sleep when required. Short of that the only reasonable solution I can see to fix this is to create a sleep function in the sensor source code and pass this as a parameter to the library. Alternatively we can build a different sleep functions in the library, but I guess this will cause the same problems as you talked about earlier with bringing in a lot of code we do not need.

                              hekH Offline
                              hekH Offline
                              hek
                              Admin
                              wrote on last edited by hek
                              #95

                              @kolaf

                              Agree on keeping the radio specific sleeping in each driver is the best option.

                              1 Reply Last reply
                              0
                              • Z Offline
                                Z Offline
                                Zeph
                                Hero Member
                                wrote on last edited by
                                #96

                                Are we talking here about

                                (1) each radio driver having its own full sleep library to put the processor to sleep (potentially in addition to the sleep library used by the main sketch), or

                                (2) just each radio driver having its own function to put its radio into low power mode with/without IRQ?

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  kolaf
                                  Hero Member
                                  wrote on last edited by
                                  #97

                                  Just (2)

                                  1 Reply Last reply
                                  0
                                  • Z Offline
                                    Z Offline
                                    Zeph
                                    Hero Member
                                    wrote on last edited by
                                    #98

                                    Good. Let's call it prepare-to-sleep or power-down or something rather than sleep.

                                    K 1 Reply Last reply
                                    0
                                    • Z Zeph

                                      Good. Let's call it prepare-to-sleep or power-down or something rather than sleep.

                                      K Offline
                                      K Offline
                                      kolaf
                                      Hero Member
                                      wrote on last edited by
                                      #99

                                      @Zeph Fair enough.

                                      Since I'm not getting any response on their mailing list, perhaps we should just go ahead and implement something. My plan is to create a virtualised powerdown in RHGenericDriver and then implement a reasonable default at least for the two radios we use. We can then expand this as we gain more experience. I know that for the RF69 driver this should be no more than five minutes work. Does anyone want to take care of your radios?

                                      K 1 Reply Last reply
                                      0
                                      • K kolaf

                                        @Zeph Fair enough.

                                        Since I'm not getting any response on their mailing list, perhaps we should just go ahead and implement something. My plan is to create a virtualised powerdown in RHGenericDriver and then implement a reasonable default at least for the two radios we use. We can then expand this as we gain more experience. I know that for the RF69 driver this should be no more than five minutes work. Does anyone want to take care of your radios?

                                        K Offline
                                        K Offline
                                        kolaf
                                        Hero Member
                                        wrote on last edited by
                                        #100

                                        If it works out, we can send them a patch :-)

                                        1 Reply Last reply
                                        0
                                        • K kolaf

                                          Hi guys,

                                          I have received my Moteinos and anarduinos with RFM69HW radios. The anarduino webpage recommends a radio library called RadioHead which supports multiple radio tips and provides a common API for communication. http://www.airspayce.com/mikem/arduino/RadioHead/

                                          It even supports quite complex things such as mesh networks. It currently supports the following radios:

                                          • RH_RF22 Works with Hope-RF RF22B and RF23B based transceivers, and compatible chips and modules, including the RFM22B transceiver module. Supports GFSK, FSK and OOK. Access to other chip features such as on-chip temperature measurement, analog-digital converter, transmitter power control etc is also provided.
                                          • RH_RF69 Works with Hope-RF RF69B based radio modules, such as the RFM69 module, (as used on the excellent Moteino and Moteino-USB boards from LowPowerLab http://lowpowerlab.com/moteino/) and compatible chips and modules such as RFM69W, RFM69HW, RFM69CW, RFM69HCW (Semtech SX1231, SX1231H). Also works with Anarduino MiniWireless -CW and -HW boards http://www.anarduino.com/miniwireless/ including the marvellous high powered MinWireless-HW (with 20dBm output for excelent range). Supports GFSK, FSK.
                                          • RH_NRF24 Works with Nordic nRF24 based 2.4GHz radio modules, such as nRF24L01 and others. Also works with Hope-RF RFM73 and compatible devices (such as BK2423). nRF24L01 and RFM73 can interoperate with each other.
                                          • RH_NRF905 Works with Nordic nRF905 based 433/868/915 MHz radio modules.
                                          • RH_RF95 Works with Semtech SX1276/77/78 and HopeRF RFM95/96/97/98 and other similar LoRa capable radios. Supports Long Range (LoRa) with spread spectrum frequency hopping, large payloads etc. FSK/GFSK/OOK modes are not (yet) supported.
                                          • RH_ASK Works with a range of inexpensive ASK (amplitude shift keying) RF transceivers such as RX-B1 (also known as ST-RX04-ASK) receiver; TX-C1 transmitter and DR3100 transceiver; FS1000A/XY-MK-5V transceiver; HopeRF RFM83C / RFM85. Supports ASK (OOK).
                                          • RH_Serial Works with RS232, RS422, RS485, RS488 and other point-to-point and multidropped serial connections, or with TTL serial UARTs such as those on Arduino and many other processors, or with data radios with a serial port interface. RH_Serial23 provides packetization and error detection over any hardware or virtual serial connection.
                                          • RH_TCP For use with simulated sketches compiled and running on Linux. Works with tools/etherSimulator.pl to pass messages between simulated sketches, allowing testing of Manager classes on Linux and without need for real radios or other transport hardware.
                                            ``

                                          Seeing as the radio that is currently supported by MySensors is also supported by RadioHead I was wondering if anyone was interested in helping me porting MySensors to work with the RadioHead library. This will greatly increase the versatility of the MySensors library and magically allow it to work with a range of different radios :-).

                                          I have briefly looked at the MySensors source code and it looks like most of the changes have to be done in MySensors.h and .cpp files.

                                          I am willing to take a stab at it, but as everyone else I am limited on time. Still, it looks like it should not be a very difficult task. As discussed in another thread, it should be sufficient either to subclass the new radio library and replace a bunch of function calls, or drop the subclassing altogether and simply use the radio library as a regular included library.

                                          The obvious difficulty comes soon as MySensors requires a function that is not available in the new radio library. However, seeing as MySensors is a pretty high-level library, and the API support from radioHead seems quite good, I suspect it should be possible to get around any such problems.

                                          Anyway, I'm thinking of creating a branch of the library and spending a few hours trying to port it and get some basic functionality to work. Is anyone else is any value in this it would be great to have some help :-)

                                          K Offline
                                          K Offline
                                          kolaf
                                          Hero Member
                                          wrote on last edited by
                                          #101

                                          Scratch my previous messages. I took a new look at the documentation and there appears to be a function setMode which can set the radio to TX, RX, and idle. I think the idle mode is as close as you come to sleeping, and I know that several of the drivers have a function called setIdleMode which you can use to define how the radio sleeps. This means that we can initialise the sleep function in the same way as we initialise the the other radio specific parameters (e.g. power and frequency), and then simply set the radio to the generic idle mode when sleeping.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          18

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular