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