Connect sensors directly to the Gateway (again)



  • Hi guys!
    I know is something already discussed several times: is it possible to connect sensors directly to the gateway with no need of an additional separate arduino sensor? Since the gateway cannot listen itself and since the gateway is already busy with its work it seems difficult.
    But in the development branch there's an example that makes me think it's possible:

    void setup() { 
      // Setup locally attached sensors
    }
    
    void presentation() {
     // Present locally attached sensors 
    }
    
    void loop() { 
      // Send locally attached sensor data here 
    }
    

    has anyone got a gateway with sensors running successfully? Do you have any example or advise to follow?
    Thank you.
    Regards


  • Admin

    Yes, it is possible in the dev branch.



  • Hi @hek,
    yes the example I posted is exactly from the development branch, I was wondering if someone already tried to make it working.
    thank you.


  • Mod

    Yes, several people have reported that they have gotten it working.



  • I did it: https://github.com/Mihai258/MySensors2-HomeAssistant-MQTT
    Tested and working fine, examples included.



  • Just got on board, great stuff! I was able to get DHT11 to send data to the controller by commenting out #define MY_RADIO_NRF24 and add #define MY_GATEWAY_SERIAL to HumiditySensor.ino in the example sketch. In my application, I need to have several gateways, each with its own type of sensors. I would like to know if there is a solution. I poked around and found #define GATEWAY_ADDRESS ((uint8_t)0) in core/MySensorCore.h. If I changed GATEWAT_ADDRESS to any other value besides 0, gateway will not send out sensor's data.


  • Admin

    Gateway will always use id 0.

    If you hook up several gateways using a serial connection, can't you identify them by the serial port on the on the other side? Or what do you intend to use as controller?

    Another option is to use a MQTT gateway and assign each one its own topic prefix.



  • I am using Raspberry Pi running Pimatic as controller and nano as sensors. I have several type of different sensors and I would like them to be USB plug-and-play. However /dev/ttyUSB gets assigned randomly so unless the nano has some kind of ID embedded, the controller has no way to associate a certain /dev/ttyUSB to a certain sensor. I am not familiar with MQTT but will start looking into it.



  • @Mihai thank you! Looking at your example I was able to make my serial gateway with a HTU21D sensor reporting temperature/humidity and listening the other sensors.
    Thank you.


  • Plugin Developer

    @punktea

    Have you checked if the USB device has a unique serial or if you can combine multiple attributes of the USB into something unique. Then use this in a udev rule. The udev rule can give the same name to the device upon each connect, if you can find unique attributes from the USB info.



  • I have looked into using udev. I found out that the Arduinos with FTDI interface do have unique serial number whereas the cheaper clones with CH341 interface do not have serial number so I have ordered nanos with FTDI chip to continue my experiment.

    I have also managed to get the gateway to send out sensor's data with a gateway id other than 0 by making one line change in core/MySensorCore.cpp:
    if (message.destination == _nc.nodeId) -> if (message.destination == 0)

    Assuming that this hack does not create other problems, I can now have multiple gateways with different ids. But I am facing a new hurdle: mysensors plugin for pimatic (controller software) is designed to support only 1 gateway! I can probably make it work by creating individual plugin for individual USB port but I am not so sure that creating a system with unsupported hacks is such a good idea. So I will pursue another approach of creating a controller with a bunch of sensor nodes hanging off USB ports.



  • @Mihai258, I can't seem to compile your MySensor2_GatewayMQTT_Sensors_Mega.ino
    It gives me these errors error : 'send' was not declared in this scope (and the same error for 'present' and 'ServerUpdate') I must be overlooking something obvious ?

    So my goal is to make build a Mega 2560 based MQTT client gateway WITHOUT radio and WITH local sensors (mostly contact-inputs) & actuators (relays). All this offcourse in development branch libs.
    My starting point would be Mihai258's example and then simply remove the MY_RADIO_NRF24 -#define's.
    Will this work ?

    Thanks,
    DirkB19



  • @DirkB19 , I just compile again this file and it works fine for me using Arduino IDE 1.6.5 on Linux, MySensors 2.0.0 beta, set Arduino/Genuino Mega or Mega 2560:

    Sketch uses 40,046 bytes (15%) of program storage space. Maximum is 253,952 bytes.
    Global variables use 1,404 bytes (17%) of dynamic memory, leaving 6,788 bytes for local variables. Maximum is 8,192 bytes.
    

    I saw this library is continuously changed, while still beta and still the same version number from long tome ago! You may remove some important definition or included libs, or the actual MySensor development version need something different into the code. I may ZIP and send to you my working version of MySensors, but should this be the right approach?



  • @Mihai
    I just updated the libs from the development branch. Still the same errors.
    I'm on Windows 10 with Arduino 1.6.6
    Not sure but if you could send me a ZIP I'll give it a try.
    Grtz


  • Mod

    @DirkB19 when you update the libraries, do you delete the entire MySensors folder first? Adding the new version on top of the old doesn't work, the old version must be obliterated first 🙂



  • @mfalkvidd
    aha ! That trick worked ! Thanks a lot !
    I guess 'newbie' is the word for me 🙂

    But coming back to my second question about this MQTT Client Gateway without radio and with local sensors and actuators ... will it work ?
    If I have the time I will find out by trial-and-error tonight.

    Bye



  • Ok, so I tried MQTT Client Gateway without radio and with local sensors and actuators and it works !!

    The MQTT topic shows the node-id as 0, which makes sense as it is a gateway.

    One thing I noticed, is that the Gateway occasionally seems to loose connection with the MQTT broker and then it shows "Attempting to connnect to MQTT broker ..." in the serial log.

    I suspect that my heavy void loop() occupies the CPU too much ?
    (I'm debouncing 16 contact inputs without the debounce library, without waits, without interrupts)

    Also sending a relais change status from OpenHab takes a few seconds before it actually gets changed on the Mega.
    OpenHab publishes right away (I see it on the MQTT monitor), but then it seems to take time before the
    void receive(const MyMessage &message) picks it up and changes the relais.

    I will do some more testing to see where the problem lies.
    Grtz,
    DirkB



  • @DirkB19 It may take some time to follow the debounce procedure for each of the 16 inputs. For me, I have no big problems with delay, the commands act almost instantly. I do not use debounce, since no physical input there, while my node use 4 relays, several sensors, IR receiver (this take some time, but no big delay).



  • hi. now that 2.0 it 's released .I'm upgrading my few sensors. But i was reading about diferences i couldn't find any example of a gateway + node integrated.
    my doubt is how to send sensor mensage? send() is used to send message to the air ,but if the node is the same as the gw what command do i use?the same?



  • @Tmaster said:

    hi. now that 2.0 it 's released .I'm upgrading my few sensors. But i was reading about diferences i couldn't find any example of a gateway + node integrated.
    my doubt is how to send sensor mensage? send() is used to send message to the air ,but if the node is the same as the gw what command do i use?the same?

    If you read at the top of this thread, there's a post from @Mihai - there's a very good example there - look at this:

    https://github.com/Mihai258/MySensors2-HomeAssistant-MQTT/blob/master/Gateway/MySensor2_GatewayMQTT_Sensors_Mega/MySensor2_GatewayMQTT_Sensors_Mega.ino

    And yes, you still use send() to send messages.

    • Jan


  • but how gateway node knows that what i send from "embebbed sensor" is to "process" there and will not send through air? its on code that will stay on id 0(gateway)?
    I know it can be an stupid question for who know the mysensors library in "its core" but not for me 😛

    I want assure that my power meter is uploading measures by serial and not by air,and making unnecessary use from nrf24 modules that cam be used for receive messages from the other nodes .


  • Admin

    @Tmaster
    You give each sensor a child id (0-254) in the node.



Suggested Topics

  • 20
  • 5
  • 15
  • 6
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts