This is quick post on how to interface enocean Pi to your laptop and use it with openHAB running from your laptop. In this post, I'm using Ubuntu 14.04 as my OS with openHAB 1.5 installed.
As my raspberry pi will be arriving a little late, I set out to find out whether it's possible to interface enocean pi to my laptop. Searching on google I found that Enocean Pi module uses only four pins from raspberry pi - VCC 3.3V, TXD, RXD, and GND. It immediately came to me that with an USB to TTL serial converter it is possible to interface the enocean module to my laptop. But there is a small problem -- I need a 3.3V USB to TTL serial converter and what I have is a 5V converter. Either I had to buy new converter or make a simple level shifter circuit. It's sunday so no shops will be open. I thought of postponing my plan to next weekend ( or dump the plan in case I receive my rPi this week ). When I'm about to stop the tinkering for the day, my eyes fell on "Ti Connected Launchpad" which I got as a part of my past roadtest. It is USB programmable and has a debugger too. Can I use it as my USB to TTL serial converter. I rushed to TI connected launchpad site and checked the specifications. PERFECT!!! This guy operates at 3.3V and perfectly fits my puzzle.
What all I need to do is to write a small code on Code Composer Studio, compile it and upload it to launchpad. The code will just set up two serial ports in my launchpad -- one I connects to my laptop and other to my enocean pi -- and acts as a serial repeater. And it worked perfectly well. Only problem I faced was I initially set baudrate as 115200 and tried to connect via my serial monitor. Nothing happened. After a few minutes I was able to debug the problem and fix it.
These are a few pics while I was setting up the circuit :
The last two above are fully assembled circuit along with rocker switch.
With my serial monitor(moserial for ubuntu) I am able to see the hexdump of the communication happening. Only rocker switch is working at this moment, may be others are out of charge.
In my serial monitor, I'm able to get this hexdump while pressing the rocker switch. Each line corresponds to either one press or one release.
// Rocker Switch // |*| | // | | |......antenna 55 00 07 07 01 7A F6 50 XX XX XX XX 30 01 FF FF FF FF 2B 00 5E // Press 55 00 07 07 01 7A F6 00 XX XX XX XX 20 01 FF FF FF FF 2C 00 86 // Release 55 00 07 07 01 7A F6 50 XX XX XX XX 30 01 FF FF FF FF 2C 00 35 // Press 55 00 07 07 01 7A F6 00 XX XX XX XX 20 01 FF FF FF FF 2C 00 86 // Release 55 00 07 07 01 7A F6 50 XX XX XX XX 30 01 FF FF FF FF 2B 00 5E // Press 55 00 07 07 01 7A F6 00 XX XX XX XX 20 01 FF FF FF FF 2B 00 ED // Release // | | | // |*| |......antenna 55 00 07 07 01 7A F6 70 XX XX XX XX 30 01 FF FF FF FF 32 00 4A // Press 55 00 07 07 01 7A F6 00 XX XX XX XX 20 01 FF FF FF FF 32 00 07 // Release 55 00 07 07 01 7A F6 70 XX XX XX XX 30 01 FF FF FF FF 2F 00 F4 // Press 55 00 07 07 01 7A F6 00 XX XX XX XX 20 01 FF FF FF FF 2F 00 B9 // Release 55 00 07 07 01 7A F6 70 XX XX XX XX 30 01 FF FF FF FF 2F 00 F4 // Press 55 00 07 07 01 7A F6 00 XX XX XX XX 20 01 FF FF FF FF 2F 00 B9 // Release
In the above dump, I've replaced a few bytes with 'XX'. I'll soon explain what they are.
Next step is to configure my openHAB installation to 'see and hear' from enocean pi.
First make sure that openHAB runtime is stopped.
Now go to '${openHAB_runtime}/configuration/openhab.cfg' file and enable openHAB binding and serial port. In my case with laptop, I've to set 'ttyACM0'. If you are raspberry pi, you may have to set 'ttyAMA0'. Edit the openhab.cfg file and add serial port.( Enocean bindings portion in the file will be usually commented. You can uncomment it and add your port )
Now go to '${openhab_runtime}/addons' and make sure that you have enocean bundle in place. Else copy it from the downloaded addons folder to this folder. The file name will be like "org.openhab.binding.enocean-1.5.0.jar"
Now open openHAB-Designer and quickly create these two files : "{$openhab_runtime}\configurations\items\model0.items" and "{$openhab_runtime}\configurations\sitemaps\model0.sitemap". Here 'model0' is my site name. Even if you already have a site running from openHAB, this site can coexist with it.
And type the following contents to the files :
// model0.items Group All Switch Rocker0 (All) {enocean="{id=XX:XX:XX:XX, eep=F6:02:01, channel=B}"} Switch Rocker1 (All) {enocean="{id=XX:XX:XX:XX, eep=F6:02:01, channel=A}"}
where you have to replace the XX with your device ID. From the serial monitor hexdump and searching through the web for a while I figured out the position of my device ID in hexdump and reused it here. Although the device ID is supposed to be printed on device, mine had none.
What I tired in the above script is to define my both rocker switches to openHAB. But only channel B is working, the one I defined with channel A is not working at this moment. I don't know what went wrong
This is the listing for model0.sitemap
// model0.sitemap sitemap model0 label="Main Menu" { Frame label="Enocean Devices" { Switch item=Rocker0 label="Rocker 0 Channel B" Switch item=Rocker1 label="Rocker 1 Channel A" } }
Before starting the runtime, edit 'start(_debug).sh' and add
-Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0
to the command in last line. Remember to replace the port with your USB port.
We're all set. Let's start by
$./start.sh
openHAB will display a few messages and will report like
00:45:53.896 INFO o.o.b.e.i.bus.EnoceanBinding[:290] - Connecting to Enocean [serialPort='/dev/ttyACM0' ].
Now we are good to go. Open chrome web browser( not Firefox! ) and goto this url
http://localhost:8080/openhab.app?sitemap=model0
where 'model0' should be replaced with your sitename.
Yup,we are done. You can see enocean switches listed in UI. Try pressing the rocker switch and see what happens.
Here is a demo video of my laptop working with enocean pi and rocker switch.
That's all for now folks, it's 1.00AM here and I've a class to attend at 8.00AM. I'll soon post my experiences with temperature sensor and reed switch.
Happy hacking,
vish