How can I communicate with the Gateway exposing a Rest API?



  • Hi all!
    I'm new using mySensors and also this will be my first project using sensors, rf24 modules, etc...I think that I'm a little bit confused about how the Gateway works...and I just would like to confirm with you which is the best way to achieve the following:

    • I have configured several Arduinos + RF24 that will control my lights, sensor temperature, etc... All the "sensors" should communicate with the Gateway, which currently is a Raspberry Pi with a RF24 module. The current gateway is an Ethernet Gateway, so the port 5003 has been exposed.
    • My idea is to be able to control each light from Internet, cell phone, or whatever...so what I had in mind was to publish a REST API inside the gateway to capture the command and then, send the correct data to the correct arduino / sensor / relay.

    For instance, if I have 2 lights, I could switch the first one ON with : POST htpp://xxxxx/1/ON

    And here my questions:

    • I have not found any example reading from a REST API from the gateway and re-sending the request to the remote sensor (using rf24) . How I have to use the gateway to achieve that?
      Do I need a Controller or I can easily add this behaviour into the Ethernet Gateway?

    I can imagine other solutions...for instance, a Python or NodeJS program acting as HTTP server, and sending MQTT messages into the gateway...but I think should be easier to consume http request inside the gateway.

    Am I wrong? Which are your thoughts?

    Thank you very much in advance!

    Regards


  • Mod

    Welcome to the forum @ivan-fontanals
    Most controllers already have a REST API. It would probably be possible to extend the gateway so it becomes a controller if you want to (and have enough time and skills to do so).



  • Thanks @mfalkvidd for your answer.
    Let's see if I understood what you meant.

    I could use an existing controller ( For instance Home assistance ), use MySensors Gateway ( without touching anything ) and link it to my arduino via RF24? I would like to avoid extending the gateway if it's not the way 🙂

    But, how will the Home assistance know that I have a new Arduino with a RF24 module? The Controller will only talk to the gateway, correct? My arduino, in the other side, will have also the MySensors library and will implement the "presentation" method...but as far as I know, this communication is against the gateway.

    So...the controller will be able to talk with this gateway and send commands to each sensor ( via gateway ) ? Is that the way?

    I have the skills ( I hope at least 🙂 )....but it's my first time that I will work with this kind of gateways, Controllers, etc...and as you can see, I'm a little bit lost about the responsibility of each component.

    Again...thank you so much!


  • Mod

    @ivan-fontanals yes you got it right. The controller can communicate with all MySensors nodes through the gateway.

    https://www.mysensors.org/about/network has an overview of how the different parts fit together. If anything is unclear, just post a question and we'll try to help.


Log in to reply
 

Suggested Topics

  • 4
  • 2
  • 2
  • 3
  • 1
  • 14

16
Online

11.2k
Users

11.1k
Topics

112.5k
Posts