How to build an alert system with Bosch XDK prototyping platform

0. Introduction

In this tutorial you will learn how to use the XDK and XDK Workbench, a programmable sensor and prototyping platform.

For a deeper explanation of what it is and what you can do with the XDK, please go to the official documentation,

  • Use the main features of XDK Workbench.
  • Send streams to Altair SmartWorks using MQTT.
  • Use some sensors of the XDK.
  • Create and use Altair SmartWorks Listeners.

TOP

1. Requirements

To follow this tutorial, you will need:

  • XDK
  • XDK Workbench installed in your computer.

You can download XDK Workbench here.

TOP

2. Project & Device Registration

Device:

If you are registered in Altair SmartWorks, you have a default device already created for you. Check your control panel and see what it looks like. Basically you need the device id_developer that might be something like defaultDevice@myusername. But if you want, you can create a new device and use it for this tutorial.

Apikey:

Now, please go to “Settings” → “Apikeys” section of the Altair SmartWorks control Panel and check your Apikey. Its a big alphanumeric token like: 98346673a6377ef1fde2357ebdcb0da582b150b00cabcd5a0d83045425407ab4. You will need this number to follow this tutorial.

3. Project Schema

In this project we will create an alert system. The XDK will send the value read by the thermometer to Altair SmartWorks using MQTT every 10 seconds. In Altair SmartWorks we will create a Listener that will send us an alert email every time the temperature is lower than 5ºC or higher than 35ºC.

4. Next steps in XDK Workbench

First of all, you have to create a project based on the example of SendDataOverMQTT. You can do it by clicking on the “SendDataOverMQTT” button of the Welcome page.

Now, in the file “SendDataOverMQTT.h” copy the next code and complete the missing data with your personal ones.

The next step is to copy this code and replace some data by yours in the “SendDataOverMQTT.c” file. We have deleted some of the default functions because we don’t use them.

Now, turn on the XDK, connect it to your computer and flash the project on it by clicking on the flash button.

5. Altair SmartWorks Listener

We have enhanced the listener creation process with our Flow Tool. This tutorial will be updated soon.

Now that everything is done on the XDK side, it's time to work with the data received. Let's create the listener in Altair SmartWorks.

A listener in Altair SmartWorks can be associated to any hierarchy entity, from Project to Device. If you associate a listener to a project, all devices below the services of that project will be affected. If you associate a listener to service, all devices below the groups of that service will be affected. And so on.

In this example, we create a listener associated with our device. This listener waits for an event to occur in the context of the device and then evaluate the content.

To create a listener go to the control panel, then to “Rules” → “Listeners” and click on the new button. Select "Device" as "entity type" and select your device on the "Id" field.

Fill the fields with the following values and continue to the next step.

  • Name: The name that you prefer
  • Description: The description that you prefer
  • Entity type: Device
  • Entity id: Your device id_developer (defaultDevice@example.example)
  • Event to listen: "Event Data Received"
  • Be sure to have your listener enabled if you want it to be executed
  • Click on the "Next Step: design the code" button to visually design the listener functionality
  • Listener creation

In the Flow editor we'll need to follow these steps:

  • Step 1: Drag and drop in the editor workspace a "switch" node and Double-click it to configure it with the values:
    Label: descriptive name of the node in the editor view. For example "If lights ON"
    If condition: select "if" and fill in the following field with the code context.data.value < 5
    Else If condition: click on the button "+ add", select again "if" and fill in the following field with the code context.data.value > 35
    Click on the button "Done" to apply the changes
  • Flow designer Step 1: Switch node
  • Step 2: Drag and drop in the editor workspace a "send email" node and Double-click it to configure it with the values:
    Label: descriptive name of the node in the editor view. For example "Send COLD email"
    To: [[Your Email Here]]
    Subject:Cold temperature
    Message:So Cold!
    Click on the button "Done" to apply the changes
  • Step 3: Drag and drop in the editor workspace a "send email" node and Double-click it to configure it with the values:
    Label: descriptive name of the node in the editor view. For example "Send HOT email"
    To: [[Your Email Here]]
    Subject: Hot temperature
    Message: So Hot!
    Click on the button "Done" to apply the changes
  • Step 4: Connect the "if" node ports to their corresponding "send email" node. From left to right, the ports correspond to the conditions added in the first step from top to bottom.
  • Flow designer Step 2, 3 and 4: Node Send Email configuration and connections
  • Step 5: Click on the "Save" button and check the listener data in the "Show" screen. You can have a look at the generated source code and use it later for debugging purposes.
  • Flow designer Step 5: Resulting listener + source code

That's all, now it's your turn to play and try to build a more complex project!

If you need help use the developers forums. Enjoy Altair SmartWorks and XDK!

TOP