Click here to Skip to main content
15,867,330 members
Articles / Internet of Things / Raspberry-Pi
Article

Temperature Sensing – Predix On Pi

17 Jan 2017CPOL4 min read 22.5K   2   4
Hooking up a Raspberry Pi to Predix; reading data from a file system and flowing that data into Predix without the need for manual intervention.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Predix is GE’s application platform for the Industrial Internet. Built on Cloud Foundry, Predix is optimized for secure connectivity and analytics at scale - in the Cloud and on the Edge.

On a sunny day in Cheltenham, England, three Predix developers from GE Aviation (myself Peter Belcher, Andrew Moffat and Sebastian Belcher) set ourselves a challenge; hooking up a Raspberry Pi to Predix and letting the data flow!

The aim of the activity was to build an understanding of how to complete one of the most fundamental uses cases; reading data from a file system and flowing that data into Predix without the need for manual intervention.

The good news is that we were able to get it working; we learned some interesting results and would like to share them with you!

The solution and its parts

The solution comprised of several components including: Predix’s User Account and Authentication and Time Series services, java app, python temperature data collector, a Raspberry Pi B+ model running the Predix Machine OSGI container, an OTS DHT11 temperature sensor and a web dashboard hosted as a standalone Predix app.

The Predix Services

The foundation of our app comprised the Predix services that, based on the Predix architecture, allow you write once and deploy on multiple devices as we proved.

Pretty much any Predix service you want to consume requires the use of the User Account & Authentication Service (UAA), and it is CRITICAL that any app you are making uses it. Because the Predix cloud is globally accessible, any data you store needs to be appropriately secured. The UAA documentation goes into this in great detail, and you can bind multiple apps to the single service if you wish.

In order to store the data that was being extracted from the PI, the Time Series Service is a perfect candidate. Already offered as a service, once you have authentication to the service set up within an app (the data pusher app in our case), you can start sending JSON!

The Time Series service uses attributes (‘tags’) within your service datastore to identify your data, so any data that is sent should also be tagged to make it easier to retrieve / analyze / slice in future. As we were writing a simple test, we just wanted to retrieve any data sent by the PI, so our JSON looks like this:

{"messageId": "12345","body":[{"name":"pidata","datapoints":}]}

Next we need a service to read the data out of the Time Series store and plot us a pretty graph. In our case, we used the dashboard seed tutorial as the base for our GUI.

Onto the Pi!

Once all the core services were in place, we were ready to get going with the Pi. Another Predix component focused on the ‘Edge’ is the Predix Machine software. This is a bit of software that has been compiled to run on many different architectures and is essentially a self-contained system within the host system.

Called the ‘OSGI Container’, you can generate one using the Predix Eclipse Plugin that allows you to download all the services required to connect and authenticate with the Predix cloud and with your java applications.

This bundle can be deployed to a remote device - the Pi in our app- and can use a whole host of Predix services natively within the container. In our case, we used websockets to establish a connection with our Time Series service, feeding our data from the sensor (data extraction written in python), through the websocket and into our timeseries service. One of the nice things about using an OSGI container is that authentication is performed within the container as a whole, removing the need for each local java services to also have its own OAuth authentication mechanism.

Done

So we are there! We built ourselves a Java app running within the OSGI container that can read data from a text file (populated by some simple python). The app sends data to the Predix Time Series data store via websockets (with the OSGI container performing OAuth validation), and then a views service that can read the data!

You can register for a Predix account here and begin using this tutorial to hook up a Raspberry Pi to Predix at Predix.io.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSample codes for the usecase explained Pin
Member 1130953418-Jun-17 20:22
Member 1130953418-Jun-17 20:22 
GeneralHelp in Time Series Pin
Shubham Dwivedi23-Jan-17 0:46
professionalShubham Dwivedi23-Jan-17 0:46 
I am also working on similar project and I need help with Time Series. I am a student and new to Predix.

Please help me how to get data which is coming to Time Series to my Java program at live time(Means as soon as it is coming to Time Series Service).

Thanks
GeneralMessage Closed Pin
23-Jan-17 6:55
professionalJayson DeLancey23-Jan-17 6:55 
GeneralRe: Help in Time Series Pin
Jayson DeLancey23-Jan-17 6:58
professionalJayson DeLancey23-Jan-17 6:58 
GeneralRe: Help in Time Series Pin
Jayson DeLancey23-Jan-17 6:59
professionalJayson DeLancey23-Jan-17 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.