TinkerForge is a company that provides generic sensors and controls for diverse use cases ranging from environmental monitoring to industrial automation. Together with Cumulocity IoT, you can:
- Build complete machine-to-machine use cases by just plugging off-the-shelf hardware components together. No configuration is required – the components are automatically discovered by the Cumulocity IoT Java agent and connected to the cloud.
- Instantly visualize sensor data and remote control devices in real-time.
In this tutorial, we will link up a Tinkerforge Weather Station to Cumulocity IoT. We will use a Weather Station configuration without an inbuilt Wi-Fi, so we will use a Raspberry Pi 4 (referred to as “RaspPi” in the description below for brevity) as an intermediary device to attach the Weather Station to the Cumulocity IoT platform. The RaspPi must have an active internet connection. The RaspPi can be integrated as a module in the Weather Station, or it can be an external device that you connect to the Weather Station via a USB cable.
Installing the Tinkerforge Brick Daemon and Brick Viewer on the RaspPi
Before we try to connect to Cumulocity IoT, we must ensure that the RaspPi and the Weather Station can communicate with each other.
For the software connection between the devices, you must install Tinkerforge’s Brick Daemon and Brick Viewer on the RaspPi. The installation instructions are provided on the Tinkerforge web page for setting up the Raspberry Pi at https://www.tinkerforge.com/en/doc/Embedded/Raspberry_Pi.html.
Checking the connection between the Tinkerforge Weather Station and the RaspPi
Now we must start the Brick Daemon and set up the Brick Viewer to communicate with the Weather Station. Note that both components must be started with sudo, to permit a USB connection between the devices.
sudo brickd sudo brickv
To start the Brick Viewer you can also use the Raspbian main menu entry Programming > Brick Viewer.
In the Brick Viewer, there is a Connect button/bar at the top of the display. Click it to see what hardware is available. The list shows enties such as the following:
- Master Brick 2.0
- LCD 20x4 Bricklet 1.2
- Barometer Bricklet
- Ambient Light Bricklet
- Humidity Bricklet
Each of the hardware items in this list has an associated tab at the top of the Brick Viewer display.
If you see such a list, this is already confirmation that the communication between the Weather Station and the RaspPi is working. As a further simple check, you can send a text message like “Hello World!” from the Brick Viewer to the Weather Station:
- In the Brick Viewer, click on the tab LCD 20x4 Bricklet.
- Click Backlight On, which causes the Weather Station’s 20x4 LCD display to light up.
- In the Text field, enter “Hello World!”, then click Send Text.
You should now see the text in the LCD display on the Weather Station.
Setting up and registering the device
To install the agent
The connection between the Tinkerforge Weather Station and Cumulocity IoT is routed over the RaspPi. The connection between the RaspPi and Cumulocity IoT is implemented by installing and running the Cumulocity IoT Java agent on the RaspPi. The Java agent on the RaspPi supports TinkerForge out of the box.
For details on installing and running the Cumulocity IoT Java agent on the Raspberry Pi, refer to the tutorial for the Raspberry Pi.
To register the RaspPi device to the platform
As a final configuration step, you must register the RaspPi device to the Cumulocity IoT platform. Instructions for doing this are also provided in the Raspberry Pi tutorial.
Interacting with the platform
To view the device in your Cumulocity IoT account, switch to the Device Management application and click All devices in the Devices menu in the navigator. By default, the device is displayed as “RaspPi <hardware model> <serial number>”.
Add the RaspPi device to a group, see Grouping devices for details. You can select an existing group or define a new group for testing purposes.
Now click the Child devices tab of the RaspPi to list the connected TinkerForge components. The display will look similar to the following:
By default, TinkerForge components are named using the name of the device that they are connected to (for example “RaspPi BCM2708 10000000e2f5ad4d”), the type of component (for example “TFHumidityBricklet”, indicating the Tinkerforge bricklet that measures humidity) and the serial number of the component (for example “nBL”). You can edit the name in the Info tab of the device.
Barometer, humidity, ambient light, moisture, distance, voltage, current and temperature bricklets
To visualize the Tinkerforge sensor data, switch to the Cockpit application. Under the Groups tab, select the group to which you assigned the RaspPi, and select the RaspPi device from the group.
Switch to the Data explorer tab of the RaspPi. Under Data points you can select which sensor readings from the Weather Station you wish to display. In the example below, the ambient light sensor (“RaspPi… Light kWS”) is selected as a device under “SELECT DEVICE”, and the data point that this sensor delivers (shown under “SELECT DATA POINT”) will be shown in the data explorer as “c8y_LightMeasurement”.
The set of data points that you select are shown in the “Data points” panel, for example:
The data explorer display updates in real time to show a graph of the sensor data over a defined period of time (for example over the last minute).
The period of time is selectable via a drop-down box adjacent to the graph.
The data is regularly collected by the Cumulocity IoT agent on the RaspPi. The frequency of the collection can be configured in the Configuration tab of the RaspPi. Typical entries in the Configuration tab are:
c8y.barometer.interval=5000 c8y.log.eventLevel=INFO c8y.light.interval=5000 c8y.log.alarmLevel=ERROR c8y.humidity.interval=5000
The settings with
.interval are given in milliseconds. If you want to change any of the settings, change the configuration value accordingly in this display and save your changes. For example, if you change the value of
c8y.light.interval from 5000 to 10000, the Data Explorer for the RaspPi in the Cockpit will show updated values for the Weather Station’s ambient light bricklet every 10 seconds.
LCD display bricklet
To operate the display from Cumulocity IoT, proceed as follows:
- In the Cockpit application, open the group that contains the RaspPi device, and select the RaspPi.
- Add a dashboard for the RaspPi, if you haven’t defined one yet. For details on adding a dashboard, see Dashboards in the User guide.
- Click Add widget.
- In the list of available widgets, select Message sending.
- Click the Display asset of the RaspPi. This adds the “Message sending” widget to the dashboard.
- In the message field of the widget, type a text such as “Hello from Cumulocity IoT”, then click Send.
- The text should now appear on the LCD Bricklet of the Weather Station.
Similarly, if you want to toggle the LCD display’s backlight on and off, create a Relay control widget, set it up to use the Display asset of the RaspPi, and use the on/off setting.
Extending the TinkerForge driver
The source code for the TinkerForge driver is publicly available at https://github.com/SoftwareAG/cumulocity-examples/ in the folder java-agent/tinkerforge-driver.