How to connect a Raspberry Pi to Altair SmartWorks using Windows 10 IoT Core and build a Notification System
- 0. Introduction
- 1. Project Schema
- 2. Raspberry Pi. Connections description
- 3. Altair SmartWorks Project and Device Registration
- 4. Code implemented on Visual Studio 2015
- 5. Creating a Notification with Altair SmartWorks Listeners
- 6. Enhancing the project
This easy tutorial helps you to build a Notification System for your home or office.
To do this, we use a Raspberry Pi with Windows IoT 10 core installed in.
In this project you will learn how to:
- Connect a Raspberry Pi to Altair SmartWorks to send data streams using Altair SmartWorks HTTP REST API
- Build a Notification App on Altair SmartWorks by programming a Listener to send an email using the SDK
- 1 x Raspberry Pi 2. Having installed Windows 10 IoT Core
- 1 x Tiny Breadboard
- 1 x Resistance 330Ω
- 1 x Pushbutton
To read the values of an analog sensor with a GPIO pin, we have relied on the proposed solution in: http://www.raspberrypi-spy.co.uk. If you want further information please read the following article:
Reading Analogue Sensors With One GPIO Pin
The connections in Raspberry Pi are extremely simple. You can see the diagram below:
- Connection schema
- Real display
If you´re 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 in this example.
Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You need this number to complete the example.
This is the C# code to Raspberry Pi. Note that some values should be replaced by your own values.
This code must be written in the MainPage.xaml.cs file. In addition, reference should link Altair SmartWorks DLL.
you can check that Data is being collected in Altair SmartWorks
- Altair SmartWorks stream list
We have enhanced the listener creation process with our Flow Tool.
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 services 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 Persisted"
- 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 alert ON"
If condition: select "if" and fill in the following field with the code context.data.alert=="on"
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 alert email"
To: [[Your Email Here]]
Subject: Alarm ON
Message: Someone has pressed the button
Click on the button "Done" to apply the changes
- Step 3: 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 and 3: Node Send Email configuration and connection
- Step 4: 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 4: Resulting listener + source code
It's time to test our listener. Send a data stream to this device, check your control panel and your email!!!
Now you know how to connect an Raspberry Pi using Windows IoT to send data to Altair SmartWorks and how to create a simple App with a single Listener and some SDK programing in Groovy. But you can enhance this project in many ways:
- Try to add a light sensor to the Raspberry Pi and send a sms considering the value of this device.
- Try to add a motion sensor to the Raspberry Pi and send other values.
- Create your own control panel to check the status of the Raspberry Pi, by building an HTML page with a request to our API to ask for the status value of your device.
- Create another device that you can interact with (like a sound alarm) and build an app combining actions between the two devices through Altair SmartWorks.