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¶
-
A Raspberry Pi 3 Model B with SD card.
-
All the following Tinkerforge products:
-
A Account.
-
The MindConnect IoT Extension Service must be activated to use the MindConnect IoT Extension. For activation contact your assigned Account Executive or Customer Success Manager or the support.
-
The following roles must be assigned to your user
mdsp:core:TenantAdmin
, assigned in Settings.mdsp:core:mcie.user
, assigned in Settings.Devicemanagement User
, assigned in MindConnect IoT Extension.
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.
- 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.
- 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. - Complete the setup by selecting the localization parameters (country, language and timezone), creating a new password and establishing the network connection.
- Check for software updates, install them and reboot the Raspberry Pi.
-
Enable SPI and SSH driver via the Interfacing Options:
- Open the terminal and execute:sudo raspi-config
- Use the arrow keys to navigate toInterfacing Options
and press Enter:
- 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. -
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¶
-
Open the terminal and execute:
java -version
-
Verify that at least Java SE Version 7 is installed on the Raspberry Pi.
Determining the Raspberry Pi's Serial Number¶
-
Execute:
cat /proc/cpuinfo
-
Note the serial number (here: 00000000fbdf4131).
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.
-
Open the terminal on the Raspberry Pi and download the agent by executing:
wget http://resources.cumulocity.com/examples/cumulocity-rpi-agent-latest.deb
-
Install the downloaded agent by executing:
sudo dpkg -i cumulocity-rpi-agent-latest.deb
Registering the Raspberry Pi in MindConnect IoT Extension¶
-
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. -
Open Devices > Registration and click Register device.
-
Select General device registration.
-
Enter the serial number of the Raspberry Pi in the field Device ID of the Device Info tab and click Next.
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.
-
The device is successfully registered with the status Pending acceptance. Click Complete.
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.
Add the host URL to the configuration file to connect the Raspberry Pi:
-
Open the terminal and open the "cumulocity.properties" file for editing.
sudo nano /usr/share/cumulocity-rpi-agent/cfg/cumulocity.properties
-
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 withhttp://
, nothttps://
. Otherwise, the device cannot connect.
Only add the host name incumulocity.properties
and leave the credentials (environment, user, password) commented out. -
Press
<CTRL+X>
to exit and enterY
to save the changes. -
Reboot the Raspberry Pi.
sudo reboot
-
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. -
Click Accept.
-
Open Devices > All devices to verify the registration. The newly connected Raspberry Pi device is listed.
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:
-
Download the latest JDK for Java 8 from Oracle, e.g.
JDK 8u200
,Linux ARM 32 Hard Float ABI
. -
Extract the files from the downloaded JDK archive.
- Open the Terminal on the Raspberry Pi.
-
Stop the Cumulocity service.
sudo service cumulocity-agent stop
-
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
-
Verify the deletion of the
device.properties
file:$ ls cumulocity.properties cumulocity.properties.template logback-debug.xml logback.xml
-
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
-
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
-
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
-
Save, close the file and reboot the Raspberry Pi
sudo reboot
-
-
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
-
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
-
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.
-
Reboot the Raspberry Pi
sudo reboot
-
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:
- Open "Devices > All devices" and select the Raspberry Pi device from the list.
- Select the "Info" tab.
- Inside the "DEVICE STATUS" panel click on the Edit button for "REQUIRED INTERVAL".
-
Enter the desired interval and save the changes.
Reading Data from the Connected Tinkerforge Sensors¶
Installing the Tinkerforge Software¶
-
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
-
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
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¶
-
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.
-
Start the Brick Viewer:
bash brickv
-
Click Connect.
-
Trigger some measurement changes, e.g. by moving an object over the Motion Detector Bricklet or by holding the Temperature Bricklet in your hand.
Checking the Sensor Connection in MindConnect IoT Extension¶
- Open Devices > All devices and select the Raspberry Pi device.
-
Open the tab Child Devices. The Tinkerforge Bricklets are listed as child devices:
TFBarometerBricklet
TFMotionBricklet
TFTemperatureBricklet
Troubleshooting sensor devices
If
FBarometerBricklet
,TFMotionBricklet
andTFTemperatureBricklet
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
-
For detailed information about a sensor, click on the sensor in the list, e.g.
TFBarometerBricklet
.-
To inspect the data received from the Barometer or Temperature Bricklet, switch to the Measurements tab.
-
To view events received from the Motion Detector, e.g.
Motion detected
/Motion ended
, switch to the Events tab.
-
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¶
-
Open the Cockpit of MindConnect IoT Extension.
-
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. -
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.
- Search for the device, e.g.
-
Enable data points from the Barometer and Thermometer Bricklets in the panel Data points to visualize the measurements in the chart.
-
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.
- Search for the device, e.g.
-
Explore the visualization chart with the selected data points from the Raspberry Pi.
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.
-
Click More... at the top of the Data Explorer.
-
Choose Download as Excel and wait for the report to be generated.
-
Click Download.
-
Open the file in Excel.
Creating Smart Rule¶
The MindConnect IoT Extension Cockpit includes a Smart Rules builder which allows you to create rules from templates.
-
Open Configuration > Global Smart Rules to display an overview of all available Smart Rule templates.
-
Select a Smart Rule template, e.g. On missing measurements create alarm.
- Click Add Smart Rule.
- Fill in the required parameters:
- Inspect the created Smart Rule.
- 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.
Related Links¶
- Insights Hub General Information
- MindConnect Products
- MindConnect IoT Extension
- MindConnect IoT Extension Documentation
- MindConnect IoT Extension Getting Started
Except where otherwise noted, content on this site is licensed under the Development License Agreement.