Skill Level: Intermediate

With this recipe, a web application enables the users to manage and control the lights of the building, also known as ‘Smart Lighting’.


  • Bluemix account
  • Watson IoT platform service
  • Wago PLC 750-8204
  • Wago KNX module 753-646
  • KNX power supply
  • Ethernet/IP interface for configuring KNX devices with ETS
  • TP wires
  • SD Card


  1. Setup the environement

    1. Clone the repository from: https://github.ibm.com/PGUF/WatsonIoTPLC
    2. Setup Wago PFC BSP (Board Support Package) on Ubuntu 14.04 by following the documentation in the repository:
      ‘HowTo: Install “WAGO-PFC-BSP-2016.2.1” on Ubuntu14.04’
    3. After completing the above step, you will have a binary image in SD card. 
    4. Enable mosquito MQTT broker by following the documentation:
      ‘HowTo: Install Mosquitto MQTT Broker and Client Library’
    5. Enable usage of persistent memory (NVRAM) by following the documentation:
      ‘HowTo: Access NVRAM from your C/C++ application’
    6. Create an image and copy it on SD card
  2. Setup PLC

    1. Attach the Wago input, output modules and KNX module with PLC and start it
    2. Give it network access and determine its IP address
    3. Connect KNX system with PLC via KNX module consisting of KNX power supply, throttle voltage and ip interface
    4. Insert the SD-Card in the PLC and restart it
  3. Setup environement for embedded programming

    1.  Follow the guide How_To_Setup_Eclipse_CDT_luna.pdf and set up eclipse for C/C++ projects in your Ubuntu machine
    2. Create and setup a C project in Eclipse, and copy three files in it from repository namely PubSubNVram.c, device.properties and Makefile 
    3. Download the certificate of Watson IoT platform: https://github.com/ibm-watson-iot/iot-python/blob/master/src/ibmiotf/messaging.pem
    4. Copy the certificate in PLC’s file system
    5. Change device.properties file according to your credentials and do not forget to update the cafile path according to the directory where you copied the certificate of Watson IoT platform
    6. Compile the program and copy the compiled file in the PLC’s file system via remote explorer in Eclipse
    7. Copy device.properties file as well in PLC via remote explorer in the same directory
  4. Setup CoDeSys Program

    1. Open the CoDeSys program from the cloned repository, and set up communication parameters
    2. Compile the program, generate SYM_XML file and run the program in PLC
  5. Configure KNX devices with ETS software tool

    1.  Open ETS and set up a project for programming KNX devices
    2. Import device catalogue in ETS project
    3. Assign physical addresses to the devices, create group addresses
    4. Import SYM_XML file for Wago KNX module and create a mapping between CoDeSys function blocks and group addresses
    5. Afterwards, download application in all KNX devices
    6. In CoDeSys program, if KNX_Status is OK then you are ready to go
  6. Connect the PLC to Watson IoT Platform

    1. Go back to PLC remote explorer and run the compiled PubSubNVram program
    2. A connection between the PLC and Watson IoT platform will be established
  7. Setup Web Application

    1.  Now to set up web application, clone the repository: https://github.ibm.com/Watson-IoT/platform-ui-components/tree/infomgmt
    2. Clone the repository:
    3. Copy the folder ToggleGroup from repository WatsonIoTPLC (step 1.1) and paste it in the custom card repository custom-card/modules
    4. Start the custom card server by running the following commands:
       Open a terminal window, go to the custom cards folder and run:
           >>npm install
       Open another terminal window and run the command:
           >>node app
    5. Go to platform-ui-components repository and open the file examples/public/config/DashBoardConfig.json
    6. Go to the section ‘settings’ and change the parameters of ‘auth’ subsection like id, org, api-key etc. according to your credentials
    7. Change the URL of custom cards server as well in
    8. Start the dashboard server by running the following commands:
       Open a terminal window, go to the dashboard folder and run:
           >>npm install
       Open another terminal window and run:
           >>cd examples
           >>npm install
           >>npm run start
    9. Start the dashboard by opening it in a browser and create a ToggleGroup custom card
    10. Add devices in the card by clicking on custom button
    11. Now, the complete system is setup and the devices can be controlled from the web application
  8. Extension of the system-Install new devices on KNX bus

    To add more devices on KNX bus and manage them from custom card, following changes have to be made in CoDeSys program and C client application program:
    Changes in CoDeSys program:
    • Categorize the device as a LightType or SensorType device
    • For LightType devices, go to CoDeSys->Data Types-> TypMyData(Struct) and increase the size of array for ‘inputLights’ and ‘ledcontrol’
    • For SensorType devices, go to CoDeSys->Data Types-> TypMyData(Struct) and increase the size of array for ‘inputSensor’
    • Add the appropriate function blocks and then assign their inputs/outputs to the corresponding array variables in POU Exchange_Variables (PRG). For example:    astData[0].inputLights[0], astData[0].inputSensor[0] etc.
    Changes in Client application program:
    • Go to C program, and update the new size of arrays (‘inputLights’, ‘ledcontrol’ and ‘inputSensor’) in typedef struct section (in the beginning of program) according to CoDeSys program.
    • If it is a light type device then add a unique device id in ‘LightIDs’ array else if it a sensor type device then add in ‘SensorIDs’ array. Device ID is the id with which it will be registered at Watson IoT platform and will also appear on custom card

1 Comment on "Smart Home Controller Connectivity Recipe for IBM Watson IoT Platform"

  1. The repo on https://github.ibm.com/PGUF/WatsonIoTPLC doesn’t exist. Could you update the article ?

Join The Discussion