element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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 Cam-e-lot - Round 8 - Man vs Binding (1)
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 13 Sep 2014 12:27 PM Date Created
  • Views 1701 views
  • Likes 0 likes
  • Comments 9 comments
  • forget_me_not
  • iot_cam-e-lot
Related
Recommended

Cam-e-lot - Round 8 - Man vs Binding (1)

amgalbu
amgalbu
13 Sep 2014

This post probably starts the most interesting part of the project: interfacing the sensor with

OpenHAB through enOcean radio protocol

 

Hardware setup

The hardware setup is shown in picture below

 

image

 

The PC runs OpenHAB and sends command to the enOcean transceiver to the Raspberry Pi board using the USB300 USB dongle. The Raspberry Pi board, in turn, sends notifications to the OpenHAB.

 

Software setup

Software setup is not so easy. Our sensor requires the use of an enOcean profile that is currently not supported neither by OpenHAB not by EOLink library. The purpose of a profile in the enOcean communication standard is easily said. The profile makes the receiver able to understand the content of the telegrams sent out by a field device. As a matter of fact, enOcean is a protocol targeted to ultra-low-power devices. For this reason, the protocol has been designed to minimize the frame length sent out by the field devices. During the installation of the field device, a "teach" telegram is sent out by the device (typically this telegram is sent out on user request, for example by pressing a push button). The "teach" telegram contains information about the profile the field device adheres to. The receiver stores the device ID and the profile. In this way, no extra data is required in the normal telegrams, because the receiver already knows (thanks to the profile it stored during the learning process) how to interpret data in the telegrams.

 

So, we are facing a complex problem because  we need to

  1. 1.       setup a development environment to build and debug OpenHAB from source code
  2. 2.       Extend the current OpenHAB enOcean binding to implement a new custom enOcean profile
  3. 3.       modify the EOLink library to support a new custom profile (I talked about building the EOLink library from source code in round 1)
  4. 4.       configure OpenHAB to use the new profile
  5. 5.       handle commands and notifications  in the sensor application running on the Raspberry Pi board

Let's start with step 1...

Build OpenHAB from source code

Here are step-by-step instructions (I installed all this stuff on a virtual machine running Windows XP)

  1. 1.       Create a local clone of the openHAB repository by running

      git clonehttps://github.com/openhab/openhab

in a suitable folder (C:\Documents and Settings\Administrator\OpenHAB)

  1. 2.       Download and install oracle jdk 1.7
  2. 3.       Download and install the Yoxos Installer from  https://yoxos.eclipsesource.com/downloadlauncher.html
  3. 4.       Download and execute the file openHAB.yoxos from  http://dl.dropbox.com/u/15535378/openHAB.yoxos

(in Linux that can be done via command line ./yoxos openHAB.yoxos ). This will install you an Eclipse IDE with all required features to develop for openHAB. Alternatively, you can install all required plugins on top of an existing Eclipse 4.2.2 installation using this update site or download a full distribution from Yoxos if you register an account there.

  1. 5.       Create a new workspace.
  2. 6.       Choose "File" -> "Import" -> "General" -> "Existing Projects into Workspace", enter your clone repository directory as the root directory and press "Finish".
  3. 7.       After the import is done, you have to select the target platform by selecting "Window" -> "Preferences" -> "Plug-in Development" -> "Target Platform" -> "OpenHAB" from the main menu. Ignore compilation problems at this step.
  4. 8.       Now you need to run code generation for a few parts of OpenHAB. To do so, go to the project org.openhab.model.codegen and run the prepared launch files. For each .launch file, select "Run As->x Generate abc Model" from the context menu. Please follow the order given by the numbers. On the very first code generation, you are asked in the console to download an ANTLR file, answer with "y" and press enter on the console. (See https://groups.google.com/forum/#!topic/openhab/QgABTJAkHOg if you're getting "Could not find or load main class org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher")
  5. 9.       All your project in the workspace should now correctly compile without errors. If you still see error markers, try a "clean" on the concerned projects. If there are still errors, it could be that you use JDK 1.6 instead of JDK 1.7. If you still have problems try (as I did)  to delete the .project from org.openhab.archetype.action and org.openhab.archetype.binding
  6. 10.   To launch openHAB from within your IDE, go to "Run" -> "Run Configurations" -> "Eclipse Application" -> "OpenHAB Runtime"

 

Unfortunately I realized that the support for sending commands to enOcean actuators provided by the enOcean binding is very poor. But, thanks to the open source community, I found another implementation of the enOcean binding here

 

To install this new binding in the OpenHAB development environment, just "File" -> "Import" -> "Existing project into workspace". A project named org.openhab.binding.aleoncean will be created.

In the Ecplise IDE, right-click in the "Project explorer" window and click "Refresh". The new Aleoncean binding will be visible in the "Project explorer" and you should be able to build and run the OpenHAB runtime.

 

Making changes to OpenHAB

During the preliminary tests I found an issue in the current implementation of OpenHAB of the Contact item.

The "Contact" item does not support the On/Off values (just Open/Closed). Because I'd like to set contact status using On/Off values, I made the following change to the ContactItem.java file (in org.openhab.core.library project)

      private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<Class<? extends State>>();

       private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<Class<? extends Command>>();

      

       static {

             //New code begins here

             acceptedDataTypes.add(OnOffType.class);

             //New code ends here

             acceptedDataTypes.add(OpenClosedType.class);

             acceptedDataTypes.add(UnDefType.class);

       }

      

       public ContactItem(String name) {

 

 

Making changes to Aleoncean binding

In the Aleoncean binding, I found an issue related to the ConverterFactory class. The getConverterFactory method of the ConverterFactory class always returns null because the checkTypeClass method looks for accepted commands, but a Contact item does not support any command. So I changed the checkTypeClass method as shown below

    private static boolean checkTypeClass(final Class<? extends StandardConverter> converterClass,

final List<Class<? extends State>> acceptedDataTypes,

final List<Class<? extends Command>> acceptedCommandTypes) {

        try {

            final Field fieldStateType = converterClass.getField(FIELD_STATE_TYPE_CLASS);

            final Field fieldCommandType = converterClass.getField(FIELD_COMMAND_TYPE_CLASS);

 

            final Class<? extends State> converterStateTypeClass = (Class<? extends State>) fieldStateType.get(null);

            final Class<? extends Command> converterCommandTypeClass = (Class<? extends Command>) fieldCommandType.get(null);

 

            //Old code

            //return acceptedDataTypes.contains(converterStateTypeClass) &&

            // acceptedCommandTypes.contains(converterCommandTypeClass));

            //New begins code

            return acceptedDataTypes.contains(converterStateTypeClass) &&

                    ((acceptedCommandTypes.size() == 0) ||

                        acceptedCommandTypes.contains(converterCommandTypeClass));

           //New code ends here

        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {

            return false;

        }

    }

 

This is just the start... the Aleoncean binding uses an external project to implement profiles and the actual communication with the USB300 dongle.

Next step will be to modify such external project to implement the enOcean profile we need...

  • Sign in to reply
  • amgalbu
    amgalbu over 11 years ago in reply to ipv1

    Hi again

    Basically you are doing what I already did, so if you want you can start from my implementation of the RemoteDeviceEEPD20100, which also has two fields that are defined in the profile specification but that I do not currently use

    Anyway, if you to better understand how things work, I would suggest to start from package org.openhab.binding.aleocean. Here you have a Worker class (note that in java the name of the file matches the name of class, so the Worker class is in the Worker.java file). The worker class is a thread (inherits from the Runnable class) and it has a method (run()) that continously read from the USB300 dongle. Communication with the dongle is handled by the class USB300 (which implements the  ESP3Connector interface) and ESP3Reader which reads out packets from ESP3Connector. Packets read are decoded and handled in the run() method. The DeviceContainer class contains all the objects of type Device which are instatiated based on the content of the items definition file. Received packets are dispatched to the proper Device object based on enOcean device ID.

    Device class are not defined in the Aleocean binding project, but in the Aleocean library. Typically you can implement a new device by inheriting from StandardDevice and RemoteDevice. The only method that you are required to implement is the parseRadioPacket, which handles the incoming radio packets. Note that StandardDevice has a method getConn() that returns the ESPConnector object. So you can access the USB300 dongle and write out everything you want to send out

     

    This is a starting point... if you have other questions please ask!

    Best regards

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ipv1
    ipv1 over 11 years ago in reply to amgalbu

    Thanks for the reply.

    Any info you can share is highly appreciated.

     

    My intent is to modify the existing binding to receive strings from the TCM320C which I will reprogram to read an analog value via ADC and send it to the EnOcean Pi and to OpenHAB. Additionally I would like to add the functionality to send a command like you have to the same device- Essentially custom two way communication.

     

    Thanks again.

    IP

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • amgalbu
    amgalbu over 11 years ago in reply to ipv1

    Hi Inderpreet

    You are right: "Recompile OpenHAB" is not the right term: what I actually did was to start a debug session for the OpenHAB runtime. If you don't need to debug, you can just copy the binding jar file to the Addons folder

    I can't  undersand you second question: I created a new profile because  profiles implemented in the binding did not provide me with the ability to handle up to 8 actuators. This is the basic reason why I started implemented a new enOcean profile

    I don't what you intent is... but if you want to extend the existing enOcean binding with a new profile you don't need to have such an in-depth knowlegde of the source code.. Anyway I gathered some information while coding and debugging so if you want I can share that infos with you... just let me know

     

    Best regards

    Ambrogio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ipv1
    ipv1 over 11 years ago

    Good job.

    I went through the 3 posts and I have a question.

     

    Do we really need to recompile openhab if we want to just modify the EnOcean Binding?

     

    Additionally can we not just add for more equipment profiles in the existing openhab bindings?

     

    Also since I am not a Java dev, any chance anyone can document the process of how the entire communication takes place? I have seen the architectural description vides by Kai sir but I need a more code-to-code description. Like A.java is where the serial listener is, B.java is where it is connected to the binding file C.java is where the string parsing takes place etc.

     

    Thanks.

    IP

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<
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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube