Tinkerforge Weather Station

Overview

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:

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.

Prerequisites

Installing the Tinkerforge Brick Daemon and Brick Viewer on the RaspPi

Before we try to connect to Cumulocity IoT, we need to ensure that the RaspPi and the Weather Station can communicate with each other.

For the software connection between the devices, you need to 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 need to start the Brick Daemon and set up the Brick Viewer to communicate with the Weather Station. Note that both components need to 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:

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:

  1. In the Brick Viewer, click on the tab LCD 20x4 Bricklet.
  2. Click Backlight On, which causes the Weather Station’s 20x4 LCD display to light up.
  3. 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 Cumulocity IoT

As a final configuration step, you need to register the RaspPi device to the Cumulocity IoT platform. Instructions for doing this are also provided in the Raspberry Pi tutorial.

Interacting with Cumulocity IoT

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:

Child Devices

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”.

Add data point

The set of data points that you select are shown in the “Data points” panel, for example:

Selected data points

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).

Live sensor graph

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:

  1. In the Cockpit application, open the group that contains the RaspPi device, and select the RaspPi.
  2. 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.
  3. Click Add widget.
  4. In the list of available widgets, select Message sending.
  5. Click the Display asset of the RaspPi. This adds the “Message sending” widget to the dashboard.
  6. In the message field of the widget, type a text such as “Hello from Cumulocity”, then click Send.
  7. 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://bitbucket.org/m2m/cumulocity-examples in the folder java-agent/tinkerforge-driver.