element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Forget Me Not - 2 - Python, EnOcean sensors and protocol
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: kipe
  • Date Created: 8 Aug 2014 9:07 PM Date Created
  • Views 508 views
  • Likes 1 like
  • Comments 0 comments
  • forget_me_not
  • python
  • enocean
  • iot
  • iot_python
Related
Recommended

Forget Me Not - 2 - Python, EnOcean sensors and protocol

kipe
kipe
8 Aug 2014

I received my Raspberry Pi B+, EnOcean Pi and sensor kit on Wednesday. The Raspi and EnOcean Pi were easy to setup, as I expected, just do a normal install and disable the default serial console on Raspi and you’re ready to go. Other people have covered this topic already, so there’s no need for me to go over it.


Unlike most of the contestants, I didn’t install any specific software to the Pi at first, just opened a serial console with ‘screen’ and pressed the learn button on the temperature sensor, to see that I get something from the serial. As I had opened the package at work, the sensors were charged enough to send couple of commands already. Of course I couldn’t understand anything that was printed, but getting something was enough at this point.


The protocol is described very well in two documents, “EnOceanSerialProtocol3.pdf“ and “EnOcean_Equipment_Profiles_EEP_V2.61_public.pdf”. The first one contains the serial interface description, while the second concentrates on device profiles (in other words: how to interpret the data inside the serial messages).


After the initial test was done, it was time to write a small Python-script to interpret the data. I knew (from the documentation I had read) that the messages start with a header, consisting of start byte (0x55), number of data bytes, message type and checksum. The basic reading of the serial port is shown at the end of this post.


At the moment of writing, I do have a fully working parser for the data messages, with checksum checking. Also I can read the temperature from the sensor. Below is a small sample of reading my fridge temperature. Should really adjust the thermostat, it’s not keeping my beers cool enough image


2014-08-08 22:13:09,241 - enocean.listener - DEBUG - 0x01 ['0xd5', '0x8', '0x1', '0x82', '0x5d', '0xab', '0x0'] ['0x1', '0xff', '0xff', '0xff', '0xff', '0x3c', '0x0'] {u'status': 0, u'destination': 4294967295L, u'dBm': -60, u'sender': 25320875, u'learn': False}

2014-08-08 22:30:05,935 - enocean.listener - DEBUG - 0x01 ['0xa5', '0x0', '0x0', '0xd4', '0x8', '0x1', '0x81', '0xb7', '0x44', '0x0'] ['0x1', '0xff', '0xff', '0xff', '0xff', '0x4a', '0x0'] {u'status': 0, u'dBm': -74, u'sender': 25278276, u'destination': 4294967295L, u'learn': False, u'data': {u'TMP': {u'value': 6.745098039215686, u'description': u'Temperature (linear)', u'unit': u'C', u'raw_value': 212}}}

2014-08-08 22:57:29,834 - enocean.listener - DEBUG - 0x01 ['0xa5', '0x0', '0x0', '0xb0', '0x8', '0x1', '0x81', '0xb7', '0x44', '0x0'] ['0x1', '0xff', '0xff', '0xff', '0xff', '0x49', '0x0'] {u'status': 0, u'dBm': -73, u'sender': 25278276, u'destination': 4294967295L, u'learn': False, u'data': {u'TMP': {u'value': 12.392156862745098, u'description': u'Temperature (linear)', u'unit': u'C', u'raw_value': 176}}}


The log contains first the packet type (0x01 for RADIO), after this comes data bytes in the message, then optional data bytes and then the parsed data as dictionary.


Unfortunately I’ve ran into some problems with the data parsing, as the EnOcean Equipment Profiles aren’t exactly easy to use, mainly because of licensing. I have been in contact with EnOcean about this issue, and I’m hoping to resolve it somehow. At the moment, I haven’t figured out a reasonable method. I’ll write a separate blog post about these issues, when I have the time.

What next?

My first task is to try and find a solution for the issues I’m having. After this is done, I’ll be making the library public and hoping other people test the library too.

In the meantime, I’ll try and put up a simple example of the library usage by implementing an web server to show the library in action by learning new devices automatically, saving them to the database and showing the data.




Example code for reading the data from serial:

import serial

# Initialize serial port and buffer

s = serial.Serial('/dev/ttyAMA0', 57600, timeout=0.1)

buf = []


while True:

    try:

     # Read characters from serial as integers

     # reads up to 30 chars, with a set timeout

     buf += [ord(c) for c in s.read(30)]


     if 0x55 in buf:

       # Messages always start with 0x55,

       # get buffer from that point onwards

       buf = buf[buf.index(0x55):]

       try:

         # First two chars represent the data length,

         # with high bit first

         data_len = (buf[1] << 8) | buf[2]

         # Optional data length is in the next char

         opt_len = buf[3]

       except IndexError:

         # If there's an index error, the data isn't complete

         # -> continue with next iteration (to wait for additional data)

         continue


       # Message length should be 7 chars + data + optional data

       msg_len = 7 + data_len + opt_len

       if len(buf) < msg_len:

         # If buffer is too short, the data isn't complete

         continue


       # Message should be in buffer, from 0 to msg_len bytes

       msg = buf[0:msg_len]

       # Remove message from buffer by reindexing it

       buf = buf[msg_len:]


       # Print the message as list of hex codes

       print(['0x%02X' % x for x in msg])

    except KeyboardInterrupt:

     break

s.close()



  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube