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. Connect sensors directly to the Gateway (again)

Connect sensors directly to the Gateway (again)

Scheduled Pinned Locked Moved Development
gatewaysensordevelopment
22 Posts 9 Posters 14.5k Views 9 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.
  • M Offline
    M Offline
    mortommy
    wrote on last edited by
    #9

    @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.

    1 Reply Last reply
    0
    • P punktea

      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.

      martinhjelmareM Offline
      martinhjelmareM Offline
      martinhjelmare
      Plugin Developer
      wrote on last edited by
      #10

      @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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        punktea
        wrote on last edited by
        #11

        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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DirkB19
          wrote on last edited by
          #12

          @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

          M 1 Reply Last reply
          0
          • D DirkB19

            @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

            M Offline
            M Offline
            Mihai
            wrote on last edited by
            #13

            @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?

            D 1 Reply Last reply
            0
            • M Mihai

              @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?

              D Offline
              D Offline
              DirkB19
              wrote on last edited by
              #14

              @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

              mfalkviddM 1 Reply Last reply
              0
              • D DirkB19

                @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

                mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #15

                @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 :)

                D 1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  @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 :)

                  D Offline
                  D Offline
                  DirkB19
                  wrote on last edited by
                  #16

                  @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

                  1 Reply Last reply
                  1
                  • D Offline
                    D Offline
                    DirkB19
                    wrote on last edited by
                    #17

                    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

                    M 1 Reply Last reply
                    1
                    • D DirkB19

                      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

                      M Offline
                      M Offline
                      Mihai
                      wrote on last edited by
                      #18

                      @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).

                      1 Reply Last reply
                      0
                      • TmasterT Offline
                        TmasterT Offline
                        Tmaster
                        wrote on last edited by
                        #19

                        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?

                        i'm a arduino fan .Even sometimes don't undestanding how to use it :P

                        chrilleC 1 Reply Last reply
                        0
                        • TmasterT Tmaster

                          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?

                          chrilleC Offline
                          chrilleC Offline
                          chrille
                          wrote on last edited by
                          #20

                          @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
                          1 Reply Last reply
                          0
                          • TmasterT Offline
                            TmasterT Offline
                            Tmaster
                            wrote on last edited by
                            #21

                            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 :P

                            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 .

                            i'm a arduino fan .Even sometimes don't undestanding how to use it :P

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

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

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


                              15

                              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