Overview

Skill Level: Any Skill Level

Introductory know how of Watson IoT platform services Working skills on Raspberry Pi  

Ingredients

  1. Raspberry Pi Model B+
  2. EnOcean kit (i.e., a controller, sensors, switch, etc.)
  3. IBM Bluemix Account
  4. IBM Watson IoT service instance

Step-by-step

  1. Introduction

    EnOcean

    Inventor of patented energy harvesting wireless technology for use in building automation, smart home and internet of things.

    The self-powered wireless devices e.g. switches, sensors and controls built over this technology, enables monitoring of various parameters like temperature, humidity, illumination, presence, etc. with lower cost of installation and time and efficient use of energy.

    For more details, check out there website at https://www.enocean.com/

    IBM Watson IoT Platform

    The IBM Watson Internet of Things Platform is a fully managed, cloud-hosted service that makes it simple to derive value from Internet of Things (IoT) devices. When combined with the IBM Bluemix platform, Watson IoT Platform provides simple, but powerful application access to IoT devices and data. You can rapidly compose analytics applications, visualization dashboards, and mobile IoT apps. Create IoT applications that feed insights to your backend enterprise applications.

    Integrating EnOcean devices with Watson IoT Platform brings in the capabilities to smartly monitor and manage the building facilities by analyzing real-time data captured using various sensors.

  2. What to expect from this recipe

    A get-to-know system with EnOcean devices connected to Watson IoT platform. You will also be able to view EnOcean device data on the Watson IoT service page or using applications like NodeRed, etc.

    Please note this recipe will not build a system with production capabilities as Fhem, the core server used, is neither scalable nor stable enough to be used in production.

  3. Before you start

    To build this recipe you will need

    1. Raspberry Pi with Raspbian wheezy operating system. For more details refer Raspberry Pi official website: https://www.raspberrypi.org
    2. EnOcean kit with devices, for e.g. Temperature, Contact, Switch
    3. You will also need
      • telnet client to connect to the telnet port of Fhem,
      • ssh client to connect to Raspberry Pi, run commands and install packages
      • account on IBM Bluemix
      • running instance of Watson IoT service
      • Web browser to connect to IBM Bluemix
      • Perl 5.14.2 installed on Raspberry Pi
  4. High level view

    Below diagram gives a high level view of the recipe.

    Our recipe will revolve around Fhem server where we will build a module, we will call that Watson IoT Gateway that will enable Fhem to connect to Watson IoT platform and send data to it. The next 2 sections details out the EnOcean devices and Fhem.

  5. EnOcean devices and controller

    The EnOcean devices are the physical devices e.g. Temperature/Contact sensor, Switch, etc. that capture different parameters like temperature, contact, etc. and transmit all the data to EnOcean controller USB300/EnOcean Pi.

    EnOcean controller in turn makes this data available on the serial port of Raspberry Pi, for the Fhem server to read from.

    Raspberry Pi:

    Works as a hub connecting together all the hardware and software components, including the Watson IoT Gateway software component.

  6. Fhem Server (or Fhem)

    Fhem (TM) is Perl server for house automation, and is used to control household appliances e.g. lamps, shutters, etc.

    For installing Fhem on Raspberry Pi and configuring EnOcean on Raspberry Pi refer to Links and Installation sections on http://fhem.de/fhem.html

    Fhem works using logical devices, registered with the Fhem server, that connect to physical devices (e.g., USB300) where needed. In case of EnOcean logical devices are created for USB300 and EnOcean devices (e.g., temperature, contact, switch, etc.).

    Fhem server and the devices (e.g., EnOcean) connected to it can be managed by using either (1) Telnet client on port 7072 or (2) Fhem Web Client on port 8083.

    More details on this can be found on http://fhem.de/fhem.html

  7. Watson IoT Gateway

    It forms the core of this recipe, connecting EnOcean devices to Watson IoT Platform, via Fhem. This gateway runs inside the Fhem process as a library, and includes 2 core components

    • The Watson IoT embedded C client libraries:

    This is a set of API’s written in ‘C’ to connect to Watson IoT platform.

    • Watson IoT Fhem module:

    This includes a small module written in perl that enables Fhem to call Watson IoT embedded ‘C’ client API’s, enabling the link between EnOcean controller and Watson IoT Platform.

    We will later feed data to this Gateway using Fhem notifications. For more details on this see section Configure EnOcean device data

    The below diagram gives the flow of data, originating at EnOcean controller and ending at Watson IoT Platform.

  8. Architecture overview

    For details on “Fhem notify” refer http://fhem.de/commandref.html#notify

    The above diagram gives a view of various components used to build this recipe. Broadly it can be broken down into 3 parts i.e.

    1. Devices (sensors, switches, etc.)
    2. EnOcean IoT Gateway (Fhem server + Watson IoT gateway) running on Raspberry Pi
    3. Watson IoT platform on IBM Bluemix

    In the coming sections we will configure the Devices (1), Install the Watson IoT gateway (2) and view the sensor data on Watson IoT platform (3).

  9. Configure EnOcean with Raspberry Pi

    Refer following link to configure Raspberry Pi with EnOcean and install Fhem http://www.enocean.com/fileadmin/redaktion/pdf/white_paper/wp_Raspberry_talks_EnOcean.pdf

    On completion: You will have a home automation setup running. You will be able to view data from devices by running command inform timer on the telnet command line.

    Note: By default telnet server will be running on port 7072 and web server on port 8083.Refer links http://fhem.de/commandref.html#telnet and http://fhem.de/commandref.html#FHEMWEB for more information on telnet and web mode of connectivity to Fhem.

  10. Install Watson IoT Gateway package

    • Download the package
     curl -LO https://github.com/WatsonIoT-Ecosystem/iot_enocean/releases/download/1.0.1/iot-enocean_1.0-1_armhf.deb

    • Install the Watson IoT Gateway package
     sudo dpkg -i iot-enocean_1.0-1_armhf.deb

    This will install your Watson IoT Gateway named ENOCEANIOT.

    Example:

    sudo dpkg -i iot-enocean/iot-enocean_1.0-1_armhf.deb

    Selecting previously unselected package iot-enocean.

    (Reading database ... 80053 files and directories currently installed.)

    Unpacking iot-enocean (from .../iot-enocean_1.0-1_armhf.deb) ...

    Setting up iot-enocean (1.0-1) ...

    Stopping fhem...

    Starting fhem...

    Processing triggers for man-db ..

    On completion: You will have all the required libraries built and installed at appropriate location. You will configure Watson IoT gateway in the next section.

    To quickly verify that everything went fine, run the below command. To run this command open a telnet session to Raspberry Pi ip address on port 7072

    define gtyiot ENOCEANIOT:

    No output on running this command implies that everything went fine.

    Developers: Interested in getting into the intricacies of building the Watson IoTEnOcean Gateway, refer link https://github.com/WatsonIoT-Ecosystem/iot_enocean

  11. Configure Watson IoT Gateway

    • Register your new Gateway on IBM Watson IoT platform

    Follow the link to register a new gateway in Watson IoT platform https://developer.ibm.com/recipes/tutorials/how-to-register-gateways-in-ibm-watson-iot-platform/

    Once you register a new gateway save the credentials that appear on your IBM Bluemix screen. You will use these credentials later to connect your Watson IoT Gateway to Watson IoT Platform.

    Example…

    • Device Registration

    Watson IoT Gateway auto registers the devices on the first published event for the device.

    Note: You need to run the below commands either using telnet client or a web client. By default telnet server will be running on port 7072 and web server on port 8083.

    Refer links http://fhem.de/commandref.html#telnet and http://fhem.de/commandref.html#FHEMWEB for more information on telnet and web mode of connectivity to Fhem.

    • Configure Watson IoT Gateway, you installed in previous step

    #define an instance of your Watson IoT Gateway

    define gtyiot ENOCEANIOT

    #set the connect attributes of your Watson IoT Gateway.

    Note: You need to replace the values with the ones you registered your Gateway on IBM Watson IoT Platform.

    attr gtyiot authtoken xxxxxxx
    attr gtyiot gatewayId Gateway01
    attr gtyiot gatewayType iotsample-gwtype
    attr gtyiot orgId orgid
    attr gtyiot authmethod token

    • Connect to Watson IoT platform

    set gtyiot connect yes

    A success message indicates you connected successfully

    • Test your Watson IoT Gateway

    set gtyiot publishevent TESTDEVICE MYTESTDEVICE {“d” : {“temp” : 34 }}

    The 3rd argument to the above command is data and if you can view this data on IBM Watson IoT Platform then everything went fine. To view the device data on Watson IoT Platform refer section “Viewing data in Watson IoT Platform” at end of this recipe.

    On completion: You EnOcean devices are now connected to Watson IoT Platform. But before you can send your device data, you need to configure what data to send. See the next step to configure the device data that goes to Watson IoT Platform

  12. Configure EnOcean device data

    Before you can start sending EnOcean device data to Watson IoT platform, you need to setup notifications for EnOcean device events.

    To find out what events your device generates refer link http://fhem.de/commandref.html#inform

    To know more about setting up setting up notifications refer http://fhem.de/commandref.html#notify

    We will setup notifications using 3 argument syntax as shown below. Note: Notifications are the only means to feed data to our Watson IoT Gateway

    define <unique notification name> notify <device name> SET <your Watson IoT Gateway instance name> publishevent <device type> <device name> <data>

    Variable Description
    $NAME Name of the device triggering the event
    $TYPE Type of the device triggering the event
    $EVENT Contains the complete event from the EnOcean sensor e.g. RORG: A5 DATA: ODATA
    $EVTPART0…$EVTPARTn Contains the space separated event parts e.g. $EVENT0=measured temperature

    The above variables $TYPE and $NAME can be substituted for <device type> and <device name>. Device data can be accessed using $EVENT and $EVTPART0…$EVTPARTn. For details refer http://fhem.de/commandref.html#notify

    For getting <device name> registered with your Fhem server see command list. For details refer http://fhem.de/commandref.html#list

    Examples:

    define evtTemp notify EnO_Temperature set gtyiot publishevent TEMPERATURE $NAME $EVENT

    define evtSwitch notify EnO_Switch set gtyiot publishevent SWITCH $NAME $EVTPART1 $EVTPART2

    On completion: Your Watson IoT Gateway is now ready to send your EnOcean device data to Watson IoT Platform.

  13. Viewing data in Watson IoT Platform

    To view the data for the devices we will use the “Device” page of Watson IoT platform service. Go to the Watson IoT Platform dashboard(Refresh if needed) and observe that the devices are already registered. The first set of data from any device, through the IoT Gateway client will automatically register it.

    To view Device data

    Click the device whose data you want to see, you will see something like below

    Clicking any of the events will display event data

  14. Conclusion

    In this recipe we demonstrated how to integrate EnOcean devices with BM Watson IoT Platform. Developers can look at the code made available in the Github repository to understand whats happening under the hood. Developers can consider this recipe as a template for EnOcean Gateway development in IBM Watson IoT Platform.

  15. Intelligent Building u2013 IoT Starter Kit

    This IoT-ready Entrepreneur starter kit is a flexible and cost-effective gateway to developing intelligent building products for hospitals, homes, airports and other venues. It includes EnOcean self-powered sensors, a Raspberry Pi and EnOcean Pi boards from element14, and provides access to the IBM Watson IoT Platform and Bluemix services from IBM.

    This kit being more technical in nature, is targeted for makers, engineers and start-ups.

    For more details refer link https://www.element14.com/community/docs/DOC-80846

  16. Follow Up

Join The Discussion