Building MySensors serial gateway and connecting it to openHab
This is tutorial and my experience with building and connecting the Mysensors serial gateway to Raspbery Pi 2B with openhabian installed.
Check out the mysensors page for more details.
What we need:
dupont cable
Arduino Nano
Radio module
Follow video to build the serial gateway
Here is my cool “temporary” box ?
Connecting to Openhab
Follow this short tutorial. Installation and configuration.
Do this following steps to guarantee your Mysensors serial gateway will always connect properly to Raspberry Pi.
Edit following file as bellow: /etc/default/openhab2
pi@raspberrypi ~ $ cat /etc/default/openhab2 EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0:ttyUSB99"
I have to use /dev/ttyAMA0:ttyUSB99 because i have also Razberry (Z-Wave controller) installed. You can put only following if you have only MySensors Serial Gateway .
EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB99"
Here is how to set up Raspberry Pi so the MySensors Gateway connect always to ttyUSB99:
Connect the serial gateway to the linux system and execute “dmesg”. You should see something like:
[ 186.047748] usb 2-1.5: new full-speed USB device number 7 using ehci-pci [ 186.147030] usb 2-1.5: New USB device found, idVendor=0403, idProduct=6001 [ 186.147036] usb 2-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 186.147040] usb 2-1.5: Product: FT232R USB UART [ 186.147044] usb 2-1.5: Manufacturer: FTDI [ 186.147047] usb 2-1.5: SerialNumber: A40360T2 [ 186.149618] ftdi_sio 2-1.5:1.0: FTDI USB Serial Device converter detected [ 186.149659] usb 2-1.5: Detected FT232RL [ 186.149663] usb 2-1.5: Number of endpoints 2 [ 186.149667] usb 2-1.5: Endpoint 1 MaxPacketSize 64 [ 186.149670] usb 2-1.5: Endpoint 2 MaxPacketSize 64 [ 186.149673] usb 2-1.5: Setting MaxPacketSize 64 [ 186.150205] usb 2-1.5: FTDI USB Serial Device converter now attached to ttyUSB0
As we see the serial gateway is now accessible through “ttyUSB0” like: /dev/ttyUSB0. But the Number may change. It depends on the FTDI Chip and could also be something like “/dev/ttyACM0”.
But we don’t want to look for the correct name after every reboot or after we plugged out and in the serial gateway, so we add the following in
/etc/udev/rules.d/99-usb-serial.rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A40360T2", SYMLINK+="ttyUSB99"
Look at the output from “dmesg” above and change “0403”, “6001” and “A40360T2” according to your hardware.
Now plug out and plug in the serial gateway.
The serial gateway will now be accessible through “/dev/ttyUSB99”.
When you are creating, building new sensors it is important you set your Node ID.
#define NodeID 3 gw.begin(NULL, NodeID, true); //incomingMessageCallback - Callback function for incoming messages from other nodes or controller and request responses. Default is NULL. //nodeId - The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to fetch an id from controller. //repeaterMode - Activate repeater mode. This node will forward messages to other nodes in the radio network. Make sure to call process() regularly. Default in false
this would correspond to item setting
Number Humidity “Humidity [%s %%Rh]” (gHumidity)
Item is connected to Thing in Openhab PaperUI.
You might want to turn on debugging .
Check the logs by running: tail -f /var/log/openhab/openhab.log