Integrating Raspberry Pi Sensor Data via MindConnect IoT Extension - Developer Documentation
Skip to content

Integrating Raspberry Pi Sensor Data - via MindConnect IoT Extension

This guide introduces you to the underlying concept of sensor data integration from Raspberry Pi into MindConnect IoT Extension and illustrates by using of Data Explorer the visualization of the measurements. Tinkerforge sensors will be connected to a Raspberry Pi. The measured values from the sensors are transmitted to MindConnect IoT Extension for further data collection and analytic activities. You can also extend this integration to create much more aspects and assets, synchronize data in real time and also visualize and analyze the measurements via Data Explorer.

General Information

Duration: 60 mins
Tested with Insights Hub version: Release Notes 19th December 2018.

Prerequisites

Supported Tinkerforge Bricklets

Currently supported Bricklets:
Barometer, humidity sensor, ambient light sensor, moisture sensor, distance sensor, voltage sensor, current sensor, temperature sensor, PTC sensor, LCD display, 4x7 segment display, remote switch, IO16, infrared distance sensor, ultrasonic distance sensor, GPS, dual relay, motion detector.

The full list of supported Bricklets can be found in the latest version of the Cumulocity agent for Raspberry Pi in the following directories:

  • \cumulocity-rpi-agent-latest\data\usr\share\cumulocity-rpi-agent\lib\tinkerforge-2.1.2\com\tinkerforge
  • \cumulocity-rpi-agent-latest\data\usr\share\cumulocity-rpi-agent\lib\tinkerforge-driver-8.17.0-SNAPSHOT\c8y\tinkerforge

The new version of the sensors is not supported yet. However, the project is open source and anyone can contribute here.

Preparing the Raspberry Pi

This section describes how to configure the Raspberry Pi and check the main parameter and functionalities.

Linux commands

In this guide the Linux commands provided in the table will be in use. To explore other commands and get more additional information check GNU Coreutils.

Command Meaning
sudo Execute a command as administrator
cat Concatenate and display the content of files
wget Retrieve web pages or files via HTTP, HTTPS or FTP
dpkg Install, build, remove, and manage packages
cd Change directory
nano Using a command line interface as text editor
ls List information about files
bash GNU Bourne-again shell
mv Move or rename files or directories
cp Copy one or more files to another location
apt-get Search for and install software packages
install Copy files and set attributes

Installing Raspbian and Configuring the Raspberry Pi

In this step there are some general preparations, which have to be executed, if you are using the Raspberry Pi for the first time. When it was already done before, you can skip these steps and continue with checking the Java Version.

  1. Prepare the Raspberry Pi: connect monitor, keyboard, mouse, and Ethernet cable or Wi-Fi adapter to the device. Do not connect the Raspberry Pi to the power source yet.
  2. Install Raspbian with NOOBS (New Out Of the Box Software). For detailed information, refer to the Getting Started and follow the installation instructions.
    After the installation the Raspberry Pi will boot up into a graphical desktop.
  3. Complete the setup by selecting the localization parameters (country, language and timezone), creating a new password and establishing the network connection.
  4. Check for software updates, install them and reboot the Raspberry Pi.
  5. Enable SPI and SSH driver via the Interfacing Options:
    - Open the terminal and execute: sudo raspi-config
    - Use the arrow keys to navigate to Interfacing Options and press Enter:
    interfacing options
    - Go to SPI, press Enter and click Yes when asked if you would like to enable the interface. Repeat this for SSH.
    - Reboot the Raspberry Pi.

  6. Optional: Edit the localization settings after the installation via: sudo raspi-config
    Select Localisation Options, change the settings and click Finish. Then reboot the Raspberry Pi.
    Alternatively, use Raspberry Pi menu starter: Preferences / Raspberry Pi Configuration / Localisation / Set Locale / OK.

Raspberry Pi

For details about these instructions, refer to the Getting Started Guide for Raspberry Pi.

Checking the Java Version

  1. Open the terminal and execute:

    java -version
    
  2. Verify that at least Java SE Version 7 is installed on the Raspberry Pi.

    check java version

Determining the Raspberry Pi's Serial Number

  1. Execute:

    cat /proc/cpuinfo
    
  2. Note the serial number (here: 00000000fbdf4131).

    check serial number

Connecting the Raspberry Pi to MindConnect IoT Extension

Installing the Cumulocity Agent

For connecting to MindConnect IoT Extension, the Cumulocity agent must be installed on the Raspberry Pi.

Note

Within company networks you might need the internet access via guest Wi-Fi or mobile phone Wi-Fi hotspot. Otherwise, the firewall will block the download.

  1. Open the terminal on the Raspberry Pi and download the agent by executing:

    wget http://resources.cumulocity.com/examples/cumulocity-rpi-agent-latest.deb
    

    download agent

  2. Install the downloaded agent by executing:

    sudo dpkg -i cumulocity-rpi-agent-latest.deb
    

    install agent

Registering the Raspberry Pi in MindConnect IoT Extension

  1. Open MindConnect IoT Extension (https://{tenant}.mciotextension.eu1.mindsphere.io) and log in with your credentials.
    If you have any problems with the login, contact the tenant admin for providing you with the credentials.

    login mciot

  2. Open Devices > Registration and click Register device.

    register device

  3. Select General device registration.

    general device registration

  4. Enter the serial number of the Raspberry Pi in the field Device ID of the Device Info tab and click Next.

    device id

    It is not required to add your Raspberry Pi to an existing device group. This is a comfort function for structuring the device overview in MindConnect IoT Extension.

  5. The device is successfully registered with the status Pending acceptance. Click Complete.

    pending acceptance

Connecting the Agent to MindConnect IoT Extension

The Raspberry Pi is now registered in MindConnect IoT Extension, but not connected. The status Waiting for connection is displayed in the Device registration tab.

waiting for connection

Add the host URL to the configuration file to connect the Raspberry Pi:

  1. Open the terminal and open the "cumulocity.properties" file for editing.

    sudo nano /usr/share/cumulocity-rpi-agent/cfg/cumulocity.properties
    
  2. Navigate through the file using the arrow keys and add a line with the host URL of the MindConnect IoT Extension of your environment. Do not make any further changes.

    host = http://{tenant}.mciotextension.eu1.mindsphere.io
    

    Note

    Make sure the line is not commented out with a #.
    The host URL has to start with http://, not https://. Otherwise, the device cannot connect.
    Only add the host name in cumulocity.properties and leave the credentials (environment, user, password) commented out.

    change cumulocity properties

  3. Press <CTRL+X> to exit and enter Y to save the changes.

  4. Reboot the Raspberry Pi.

    sudo reboot
    
  5. Open MindConnect IoT Extension (http://{tenant}.mciotextension.eu1.mindsphere.io) and open Device > Registration. The new device status is Pending acceptance and an Accept button is displayed.

    accept device

  6. Click Accept.

  7. Open Devices > All devices to verify the registration. The newly connected Raspberry Pi device is listed.

    all devices

Note

If you still cannot see the registered device in the list All devices, execute the workaround in the next section.

Applying the Workaround for Registration / Connection Issues

Skip this section if your Raspberry Pi is listed in All devices.

Patch the installed JDK to fix the issue of the Raspberry Pi not appearing in MindConnect IoT Extension:

  1. Download the latest JDK for Java 8 from Oracle, e.g. JDK 8u200, Linux ARM 32 Hard Float ABI.

    download jdk

  2. Extract the files from the downloaded JDK archive.

  3. Open the Terminal on the Raspberry Pi.
  4. Stop the Cumulocity service.

    sudo service cumulocity-agent stop
    
  5. Delete the device.properties file.

    $ cd /usr/share/cumulocity-rpi-agent/cfg/
    $ ls
    cumulocity.properties cumulocity.properties.template device.properties logback-debug.xmllogback.xml
    sudo rm device.properties
    
  6. Verify the deletion of the device.properties file:

    $ ls
    cumulocity.properties cumulocity.properties.template logback-debug.xml logback.xml
    
  7. Check if the JAVA_HOME variable is set:

    JAVA_HOME-bash
    

    If the variable is set, the result is similar to:

    JAVA_HOME-bash: /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt: Is a directory

    Otherwise, the result is:

    JAVA_HOME environment variable is not set

  8. If the JAVA_HOME variable is not set, execute the following steps:

    • Open a new terminal inside pi@raspberrypi and make sure java is installed:

      java –version
      
    • Determine the location of the Java executable:

      whereis java
      
    • Run

      sudo nano ~/.profile
      

      open profile

    • Set the JAVA_HOME variable by adding a line which specifies the location of the Java executable, such as:

      JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt
      

      set java home variable

    • Save, close the file and reboot the Raspberry Pi

      sudo reboot
      
  9. Navigate to the Java security directory and check if the cacerts file is present:

    $ cd /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/security/
    $ ls
    blacklist blacklisted.certs cacerts java.policy java.security local_policy.jar trusted.librariesUS_export_policy.jar
    
  10. Move the cacerts file to another directory (or rename it):

    $ sudo mv ./cacerts ./cacertsbkup
    $ ls
    blacklist blacklisted.certs cacertsbkup java.policy java.security local_policy.jar trusted.librariesUS_export_policy.jar
    
  11. Copy the new cacerts file from the extracted JDK download into the security directory:

    $ cd /home/pi/Downloads/jdk1.8.0_191/jre/lib/security
    $ ls
    blacklist blacklisted.certs cacerts cacertsbkup java.policy java.security jartrusted.libraries
    $ sudo cp ./cacerts /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/security//jre/lib/security/
    $ cd /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/security/
    $ ls
    blacklist blacklisted.certs cacerts cacertsbkup java.policy java.security local_policy.jartrusted.libraries US_export_policy.jar
    

    You should see the similar results after the execution of the command. copy new cacerts

  12. Reboot the Raspberry Pi

    sudo reboot
    
  13. Repeat steps for registering the Raspberry Pi.

Changing the Measurement Interval in MindConnect IoT Extension (optional)

After registration, the Raspberry Pi can send measurements to MindConnect IoT Extension. Updates are triggered when the data changes significantly or every 3 minutes, otherwise. The interval between measurements can be changed in MindConnect IoT Extension as follows:

  1. Open "Devices > All devices" and select the Raspberry Pi device from the list.
  2. Select the "Info" tab.
  3. Inside the "DEVICE STATUS" panel click on the Edit button for "REQUIRED INTERVAL".
  4. Enter the desired interval and save the changes.

    change measurement interval

Reading Data from the Connected Tinkerforge Sensors

Installing the Tinkerforge Software

  1. Install the Brick Daemon software to the Raspberry Pi:

    sudo apt-get install libusb-1.0-0 libudev0 pm-utils
    wget http://download.tinkerforge.com/tools/brickd/linux/brickd_linux_latest_armhf.deb
    sudo dpkg –i brickd_linux_latest_armhf.deb
    

    If required, enter Y.

    Click here for screenshots of the installation process

    download Brick Daemon 1

    download Brick Daemon 2

    download Brick Daemon 3

  2. Install the Brick Viewer software to the Raspberry Pi.

    sudo apt-get install python-qt4 python-qt4-gl python-opengl python-serial python
    wget http://download.tinkerforge.com/tools/brickv/linux/brickv_linux_latest.deb
    sudo dpkg –i brickv_linux_latest.deb
    

    If asked whether to continue, enter Y.

    Click here for screenshots of the installation process

    download Brick Viewer 1

    download Brick Viewer 2

    download Brick Viewer 3

Tinkerforge with Raspberry Pi

For further information on how to use Bricks and Bricklets with a Raspberry Pi, refer to Tinkerforge.

Testing the Tinkerforge Installation

  1. Connect the Tinkerforge sensors to the Raspberry Pi:

    • Connect the Master Brick to the Raspberry Pi via USB.
    • Connect the Barometer, Temperature and Motion Detector Bricklets to the ports on the side of the Master Brick.

    connection overview

  2. Start the Brick Viewer:

    bash brickv
    
  3. Click Connect.

    Connect Brick Viewer

  4. Trigger some measurement changes, e.g. by moving an object over the Motion Detector Bricklet or by holding the Temperature Bricklet in your hand.

    Master Brick data Barometer data Thermometer data Motion Detector data

Checking the Sensor Connection in MindConnect IoT Extension

  1. Open Devices > All devices and select the Raspberry Pi device.
  2. Open the tab Child Devices. The Tinkerforge Bricklets are listed as child devices:

    • TFBarometerBricklet
    • TFMotionBricklet
    • TFTemperatureBricklet

    Child devices

    Troubleshooting sensor devices

    If FBarometerBricklet, TFMotionBricklet and TFTemperatureBricklet are not listed, execute the following steps:

    • Check if all Bricklets are properly connected to the Master Brick
    • Reboot the Raspberry Pi
    • Open a terminal and execute:
      bash brickv
    • Open a second terminal and execute following commands:
      sudo service cumulocity-agent stop
      sudo service cumulocity-agent start
      sudo service cumulocity-agent status
  3. For detailed information about a sensor, click on the sensor in the list, e.g. TFBarometerBricklet. barometer sensor info

    • To inspect the data received from the Barometer or Temperature Bricklet, switch to the Measurements tab. barometer measurements

    • To view events received from the Motion Detector, e.g. Motion detected/Motion ended, switch to the Events tab. motion detector measurements

Visualizing Sensor Data via Data Explorer

This section illustrates how to forward the data from the Device Management to the Data Explorer in MindConnect IoT Extension. The Data Explorer visualizes the data from the connected devices.

Discovering the Data Explorer in MindConnect IoT Extension

  1. Open the Cockpit of MindConnect IoT Extension. cockpit

  2. Select Data explorer to visualize data points.
    By default, the Data Explorer displays the first five data points of the selected device or group. Those data points are listed in the panel Data points.

  3. Add new data points to the Data Explorer, by clicking Add data point in the panel Data points.

    • Search for the device, e.g. RaspPi.
    • Select and add the data points from the Barometer and Thermometer Bricklet.

    add data point

  4. Enable data points from the Barometer and Thermometer Bricklets in the panel Data points to visualize the measurements in the chart.

    select data

  5. To capture information from the Motion Detector Bricklet, add event tracking by clicking Add alarm / event in the panel Alarms / Events.

    • Search for the device, e.g. RaspPi.
    • Add the events from the Motion Detector Bricklet.

      add event

  6. Explore the visualization chart with the selected data points from the Raspberry Pi.

    visualization

Data Point Visualization

The visualization is generated based on the data point properties. To adjust the visualization properties of a data point, expand the appropriate data point in the panel Data points of the Data Explorer.

Downloading a Data Report

The measurements of the data points can be downloaded as a report in Excel or CSV format.

  1. Click More... at the top of the Data Explorer.

  2. Choose Download as Excel and wait for the report to be generated.

  3. Click Download. mciot data report

  4. Open the file in Excel. report

Creating Smart Rule

The MindConnect IoT Extension Cockpit includes a Smart Rules builder which allows you to create rules from templates.

  1. Open Configuration > Global Smart Rules to display an overview of all available Smart Rule templates. global smart rules

  2. Select a Smart Rule template, e.g. On missing measurements create alarm.

  3. Click Add Smart Rule.
  4. Fill in the required parameters: smart rule 1 smart rule 2
  5. Inspect the created Smart Rule. smart rule info
  6. Verify the execution of the Smart Rule.
    • Open the Device Management.
    • Select the device targeted by the created Smart Rule and check for new alarm notifications.

Note

Alternatively, you can create a Smart Rule directly from the Data Explorer using the action menu of a data point in the panel Data points.


Except where otherwise noted, content on this site is licensed under the Development License Agreement.


Last update: June 15, 2023