In last post, I explained how I was able to connect Enocean Pi to a laptop and configure it with openHAB. It worked pretty well, but I had a hard time decoding IDs of enocean devices to configure in openHAB. I managed to get hexdumps of the serial communication happening with a serial monitor and spend some time with Enocean Serial Protocol document and Enocean Equipment Profile document to finally figure out how to extract device IDs from the hex dump.
As a part of my course curriculum, now I've started learning Python and then thought of writing a small python script to help me in coding ESP3 packets. It will be a great exercise for me to test my python learning. I started out with Google and Stackoverflow last weekend. What more fun can be there than coding some protocol decoder??
Enter Enocean Py
After 5 days from starting, I have a working prototype of my own ESP3 decoder - Enocean Py. Enocean Py is a small python script which will help you in decoding ESP3 packets and validate them. It also allows you to send some commands and decode the response.
This is a screen shot of Enocean Py's working :
Enocean Py also includes a simple API to send, receive, decode and display the packet details. Currently the following features are supported.
1. Send raw commands to Enocean gateway
2. Receive raw ESP3 data packets from Enocean Gateway
3. Decode received ESP3 packet, one at a time.
4. Display the packet details for RESPONSE type packets.
The following features will be implemented soon
1. Decoding RADIO packets
2. Support for left out RESPONSE packets for CO_COMMAND
3. Decode multiple packets from a single buffer.
Hopefully by next weekend, I can come up with a working version of Enocean Py. For those who can wait till then, you can get early snapshot of Enocean Py from https://github.com/v-i-s-h/Enocean-Py . It has a main function in the script which will demonstrate the basic usage of API.
How to use :
1. Clone the git repository to your local folder
2. Open the script in any text editor and change 'ttyPort' to the port in which Enocean Gateway is connected.
3. Save the script
4. run 'python eopy.py'
5. eopy will display basic info about your enocean gateway and start listening to radio telegrams.
5. Press Ctrl+C to stop the execution
If you are getting junk values on first execution, stop and restart the script. This is due to unread data in serial buffer( see below for details )
Known issues :
1. If a data stream with more than one packet is fetched, only first packet is decoded.
2. On starting( and after sending each command ), data read from the serial port may contain more than one packet -- additional packets are from the enocean sensors communicating to gateway. Flushing serial port is the solution for this, but I'm not able to figure out how.
Feel free to use, modify, improve and share the code I hosted. Also let me know your comments.
Cheers,
vish