Predix – Sensor Emulator in C++

Asset Details

This Topcoder challenge was focused on creating a Predix sensor emulator in C++. Check out the original challenge and dive into the winning Asset details below.

Congratulations to cjalmeida for taking first place in the challenge and providing us with his “winner’s asset details and description”.

Winner's Asset Details & Description

This is a sample application built using modern C++14 features that simulates the collection of sensor data and uploads to GE Predix “Asset” and “Timeseries” services. The application is built based on POCO library (mainly for networking) and should run on any recent Linux device. The use case would be a field-deployed data collector — likely implemented on a cheap embedded ARM SoC board — fetching data from multiple cheap sensors. An INI file contains the configuration needed to connect to the Predix services.

All communication is secured via TLS. You just need to provide a valid CA bundle. On start, the application securely retrieves an access token from the User Authentication and Authorization Service (UAA). This service uniquely authenticates each end node and makes sure rogue devices have no access to the other services.

Then it starts sampling data from a “mocked sensor” implementation. If the data is considered “OK,” the content is sent to the Timeseries Service (TS), a Predix-hosted database that specializes in storing time-dependent sensor data. A persistent Secure WebSocket (wss://) connection to TS is established and kept alive to minimize connection overhead. The API is message-oriented, using the a send-and-ack mechanism. The data is sent asynchronously (via threading) to avoid blocking the sampling operation. An intermediate queue and reconnect logic are used to make sure data is not lost on flaky connections.

If the sampled mock sensor data is an “ERROR,” a notification is sent to the Asset service, a hosted document-oriented database. This communication is made via regular HTTPS using a REST-oriented API. Again, the communication is asynchronous.

The configuration assumes you have provisioned the required UAA, TS, and Asset Predix services. To simplify testing, the code also provides a Python script that fully automates the provisioning step from a brand-new Predix account. This also shows how to automate node fleet maintenance using the CloudFoundry client and Predix management APIs.

Finally, to simplify development, the application is cross-platform (i.e., Windows, Linux, and MacOS), works on GCC/Clang/VC++, and uses CMake as common build tool. Also, while not common in C/C++ land, the code relies on for dependency management; pulling external dependencies should be as simple as it is on Java/Python/Node.

Topcoder Winner



C C++ Predix



Are you ready for Predix?