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.
  • YveauxY Offline
    YveauxY Offline
    Yveaux
    Mod
    wrote on last edited by Yveaux
    #102

    Just a small update on my effort to get RadioHead & MySensors working with nRF24L01+...
    I managed to get the node configured correctly using the MySensors 'defaults'.
    I see data getting sent over the air (as my sniffer captures it). The only data on air, captured by Wireshark, is:

    ff:7e:01:00:ff:7e:00:52:00:01:01:00
    ff:7e:02:00:ff:7e:00:53:00:01:01:00
    ff:7e:03:00:ff:7e:00:54:00:01:01:00
    ff:7e:04:00:ff:7e:00:55:00:01:01:00
    etc.
    

    Roughly 4 seconds apart.
    I have to dive deeper into the protocol , but I suspect this is the node sending broadcasting requests to find a parent.
    The gateway doesn't acknowledge these broadcasts yet...
    Fixed a few small issues in the nRF24 driver along the way (see https://github.com/Yveaux/RadioHead/commits/MySensors/RadioHead/RH_NRF24.cpp)
    Seems like I'm almost there!

    Some things I miss in the library:

    • Normally the nRF24 changes its destination address when sending to the destination's node address. The current driver/RadioHead implementation just always broadcasts and the header of the data determines which node the data is really for. This means any node within range will always have to process all messages coming in to determine if they are meant for it or not. From a generic driver point-of-view I understand this approach, but it ignores powerful functionality of the nRF24. As the nRF24 is still the main radio target for the MySensors library we might have to think about a solution.
    • The library does not use the auto-acknowledge feature of the nRF24 but instead seems to retry on application level. Another nice feauture of the nRF24 which remains unused...

    http://yveaux.blogspot.nl

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

      I would guess it is a arp request. Weird that it does not use the radio properly, I think both addressing and retransmission works well with rf69.

      1 Reply Last reply
      0
      • hekH Offline
        hekH Offline
        hek
        Admin
        wrote on last edited by
        #104

        Using auto-ack would be impossible (i think) using the in radioheads mesh-setup where every message basically is a broadcast.

        I wondoer if it would it be possible to implement a mySensors class similar to RHMesh which actually works like MySensors do today using a star-topology and direct-addressed messages?

        K T 2 Replies Last reply
        0
        • hekH hek

          Using auto-ack would be impossible (i think) using the in radioheads mesh-setup where every message basically is a broadcast.

          I wondoer if it would it be possible to implement a mySensors class similar to RHMesh which actually works like MySensors do today using a star-topology and direct-addressed messages?

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

          radiohead uses direct messaging, with an arp protocol and route discovery to build local routing tables, much as original mysensors. At least as far as I understand it.

          Do you use the same library in both the sensor and gateway? It won't work of you mix network layer protocols.

          K 1 Reply Last reply
          0
          • K kolaf

            radiohead uses direct messaging, with an arp protocol and route discovery to build local routing tables, much as original mysensors. At least as far as I understand it.

            Do you use the same library in both the sensor and gateway? It won't work of you mix network layer protocols.

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

            @kolaf with hop by hop acknowledgements

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

              @Yveaux said:

              ff:7e:01:00:ff:7e:00:52:00:01:01:00

              Ok, read a bit through the docs. Apparently this is what is sent:

              RHDatagram:  ff:7e:01:00     (TO:FROM:ID:FLAGS)
              RHRouter:    ff:7e:00:52:00  (DEST:SOURCE:HOPS:ID:FLAGS)
              RHMesh:      01:01:00        (ROUTE_DISCOVERY_REQUEST:<RESERVED>:DEST)
              

              Therefore the destination and source address are sent TWICE (destination even 3 times with nRF24, as the destination address is part of the nRF24 header). An ID byte (incremented with each message sent) is also present in RHDatagram & RHRouter.
              After the route is known, sending through RHMesh still requires 1 byte to indicate application payload is transmitted.
              For short, Every message will require 10 bytes header, at least, to which the MySensors payload is added (including its own header of currently 4 bytes) giving at least 14 bytes overhead of 32 bytes total.
              To me this feels like too much....

              http://yveaux.blogspot.nl

              T 1 Reply Last reply
              0
              • hekH Offline
                hekH Offline
                hek
                Admin
                wrote on last edited by
                #108

                Yep, a 10 byte header is a lot.

                K 1 Reply Last reply
                0
                • hekH hek

                  Yep, a 10 byte header is a lot.

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

                  @hek Maybe we should just use reliable datagram. The ms header could contain just "source, destination, and last", and rhreliabledatagram deals with hop by hop ack and addressing.

                  YveauxY 1 Reply Last reply
                  0
                  • K kolaf

                    @hek Maybe we should just use reliable datagram. The ms header could contain just "source, destination, and last", and rhreliabledatagram deals with hop by hop ack and addressing.

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

                    @kolaf Just because of the size of the header?
                    I would prefer to use the RadioHead library also for routing, but maybe the current implementation can be made more efficient, in terms of header length and also code space.
                    Currently I can barely fit in a simple sensor example and Ethernet gateway also gives warning about ram usage...

                    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.

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

                      @kolaf said:

                      I'm very curious to see whether you can get my version of the library working with your radio.

                      Got it to work with nRF24!
                      Still some issues every now and then and I have to verify the radio config but messages are exchanged between node & gateway, using RHMesh.

                      Can't believe I ran into the same trap again as with the CRC8 calculation (remember @hek ?)
                      sizeof(message) in MySensor::sendWrite is 33 bytes, which is one byte more than nRF24 can send, causing all transmissions to fail...

                      See my changes here: https://github.com/Yveaux/Arduino/commits/radiohead_port

                      http://yveaux.blogspot.nl

                      K 1 Reply Last reply
                      0
                      • YveauxY Yveaux

                        @kolaf said:

                        I'm very curious to see whether you can get my version of the library working with your radio.

                        Got it to work with nRF24!
                        Still some issues every now and then and I have to verify the radio config but messages are exchanged between node & gateway, using RHMesh.

                        Can't believe I ran into the same trap again as with the CRC8 calculation (remember @hek ?)
                        sizeof(message) in MySensor::sendWrite is 33 bytes, which is one byte more than nRF24 can send, causing all transmissions to fail...

                        See my changes here: https://github.com/Yveaux/Arduino/commits/radiohead_port

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

                        @Yveaux maybe I could give you write access to my repository. Will be much easier if we are working on the same thing, less hassle with keeping up to date.

                        YveauxY 1 Reply Last reply
                        0
                        • K kolaf

                          @Yveaux maybe I could give you write access to my repository. Will be much easier if we are working on the same thing, less hassle with keeping up to date.

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

                          @kolaf OK, fine, but it's working now so I don't plan on much changes anymore.
                          Could you merge all 1.4 changes to your fork? I feel it's quite running behind.
                          Next I'll focus on a Wireshark dissector, as I'm not convinced everything on air is needed/correct...
                          It would be great BTW if the sniffer would work with the Radiohead drivers, so it supports different radios....

                          http://yveaux.blogspot.nl

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

                            I pulled in the latest eight commits, merged, and pushed. I think I should be completely up-to-date with the development branch.

                            1 Reply Last reply
                            0
                            • YveauxY Yveaux

                              @kolaf OK, fine, but it's working now so I don't plan on much changes anymore.
                              Could you merge all 1.4 changes to your fork? I feel it's quite running behind.
                              Next I'll focus on a Wireshark dissector, as I'm not convinced everything on air is needed/correct...
                              It would be great BTW if the sniffer would work with the Radiohead drivers, so it supports different radios....

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

                              @Yveaux I think you have to submit a pull request for me to merge your changes in.

                              YveauxY 1 Reply Last reply
                              0
                              • K kolaf

                                @Yveaux I think you have to submit a pull request for me to merge your changes in.

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

                                @kolaf I think I just merged everything in your repo... This is all a bit new to me ;-)

                                http://yveaux.blogspot.nl

                                K 1 Reply Last reply
                                0
                                • YveauxY Yveaux

                                  @kolaf I think I just merged everything in your repo... This is all a bit new to me ;-)

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

                                  @Yveaux Got it, thanks.

                                  1 Reply Last reply
                                  0
                                  • hekH hek

                                    @kolaf

                                    Memory is usually not a big problem. When I turn off debug messages a normal actuator (e.g. DimmableLED) produces the following.

                                    Sketch uses 11,868 bytes (36%) of program storage space. Maximum is 32,256 bytes.  
                                    Global variables use 423 bytes (20%) of dynamic memory, leaving 1,625 bytes for local     variables. Maximum is 2,048 bytes.
                                    

                                    But if you start combining sensors using external libraries such as OneWire, LEDDisplay I guess it adds up. The RadioHead library is very well written and would probably not add much overhead.

                                    Inclusion mode is only handled between gateway and controller so it would not be affected.
                                    Gateway would probably not need much changed. But the MyMessage class would need some tweaking lifting out the routing part.
                                    RadioHead library does not store any routing info in eeprom so everytime a node is powered up it need to rebuild this.

                                    T Offline
                                    T Offline
                                    ToSa
                                    Code Contributor
                                    wrote on last edited by
                                    #118

                                    @hek said:

                                    RadioHead library does not store any routing info in eeprom so everytime a node is powered up it need to rebuild this.

                                    That's beneficial in terms of available EEPROM space for other purposes - but would be interesting to see the shit-storm after a power-outage when all nodes power-up at the same time and need to rebuild the entire network tree from scratch?

                                    1 Reply Last reply
                                    0
                                    • hekH hek

                                      Using auto-ack would be impossible (i think) using the in radioheads mesh-setup where every message basically is a broadcast.

                                      I wondoer if it would it be possible to implement a mySensors class similar to RHMesh which actually works like MySensors do today using a star-topology and direct-addressed messages?

                                      T Offline
                                      T Offline
                                      ToSa
                                      Code Contributor
                                      wrote on last edited by
                                      #119

                                      @hek said:

                                      I wondoer if it would it be possible to implement a mySensors class similar to RHMesh which actually works like MySensors do today using a star-topology and direct-addressed messages?

                                      @Kolaf said:

                                      @hek Maybe we should just use reliable datagram. The ms header could contain just "source, destination, and last", and rhreliabledatagram deals with hop by hop ack and addressing.

                                      @Yveaux said:

                                      I would prefer to use the RadioHead library also for routing, but maybe the current implementation can be made more efficient, in terms of header length and also code space.
                                      Currently I can barely fit in a simple sensor example and Ethernet gateway also gives warning about ram usage...

                                      Just a thought (I did NOT review the entire RH code) - from the RH documentation it sounds like we could use the RH Drivers without using any of the RH Managers - keeping routing etc. within MySensors responsibility.
                                      Just checking as it appears that @kolaf and @Yveaux have spent significant time reviewing the code and I would want to understand if that's an option or a totally stupid idea :)

                                      K 1 Reply Last reply
                                      0
                                      • T ToSa

                                        @hek said:

                                        I wondoer if it would it be possible to implement a mySensors class similar to RHMesh which actually works like MySensors do today using a star-topology and direct-addressed messages?

                                        @Kolaf said:

                                        @hek Maybe we should just use reliable datagram. The ms header could contain just "source, destination, and last", and rhreliabledatagram deals with hop by hop ack and addressing.

                                        @Yveaux said:

                                        I would prefer to use the RadioHead library also for routing, but maybe the current implementation can be made more efficient, in terms of header length and also code space.
                                        Currently I can barely fit in a simple sensor example and Ethernet gateway also gives warning about ram usage...

                                        Just a thought (I did NOT review the entire RH code) - from the RH documentation it sounds like we could use the RH Drivers without using any of the RH Managers - keeping routing etc. within MySensors responsibility.
                                        Just checking as it appears that @kolaf and @Yveaux have spent significant time reviewing the code and I would want to understand if that's an option or a totally stupid idea :)

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

                                        @ToSa It is definitely not a stupid idea, it is a variation of what I suggested previously which you quoted in your post (using the reliable datagram manager instead). It is a question of the abstraction level we want to use. Personally I prefer to use a library where everything is built in and that has widespread use. This gives us much more features for "free", and depending on the user base also a lot more testing. However, it turns out that not everything is perfect. The header is too big, and the library is perhaps not as efficient as it could be.

                                        This boils down to whether we should do things more efficiently ourselves, or try to fix the library, either officially or unofficially. It looks like the maintainer of the project is very open to suggestions. In fact, I just saw a post where he said he had implemented a generic powerdown mode for all the drivers that I suggested a few days ago. My guess is that if we work with him we could get a lean and mean radio library which could benefit both the MySensors project and the Arduino community as a whole. There appears to be people here with quite good radio knowledge, so think this could be a very powerful combination. Still, it is a question of time, effort, and priorities...

                                        YveauxY 1 Reply Last reply
                                        0
                                        • K kolaf

                                          @ToSa It is definitely not a stupid idea, it is a variation of what I suggested previously which you quoted in your post (using the reliable datagram manager instead). It is a question of the abstraction level we want to use. Personally I prefer to use a library where everything is built in and that has widespread use. This gives us much more features for "free", and depending on the user base also a lot more testing. However, it turns out that not everything is perfect. The header is too big, and the library is perhaps not as efficient as it could be.

                                          This boils down to whether we should do things more efficiently ourselves, or try to fix the library, either officially or unofficially. It looks like the maintainer of the project is very open to suggestions. In fact, I just saw a post where he said he had implemented a generic powerdown mode for all the drivers that I suggested a few days ago. My guess is that if we work with him we could get a lean and mean radio library which could benefit both the MySensors project and the Arduino community as a whole. There appears to be people here with quite good radio knowledge, so think this could be a very powerful combination. Still, it is a question of time, effort, and priorities...

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

                                          @kolaf I totally agree with you.
                                          The MySensors library currently has a solid nrf24 implementation and routing works fine (though not fully mesh) so there's no direct need to switch driver and routing layer.
                                          This is a roadmap item on which we should continue working, IMO together with the RadioHead development. The RadioHead library has only recently been developed (few months old or so) and is already very mature looking. This is very promising for the future and there's no use in developing/maintaining 2 nearly identical libraries.
                                          I think the current flaws (e.g. code & message size) can be improved with our help making it a solid base for MySensors.

                                          http://yveaux.blogspot.nl

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


                                          13

                                          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