Using Predix Mobile Services to Create a Cross-Platform App
This post introduces developers to Predix services. The scenario for the article includes preparing a simple cross-platform application based on the Cordova technology as well as interacting with Predix Mobile services. We also want to see if there any restrictions for using Predix Mobile services in a hybrid application.
To follow my examples, you need:
- the Cordova CLI
- the Cloud Foundry CLI
- the Cloud Foundry UAA CLI
- the Predix Mobile CLI
Find more information in Predix docs.
Creating a cross-platform application
After you install Cordova, create a Cordova project and add platforms you want to test. I used AngularJS to write my sample JS application.
In our case, it is not necessary to deploy the application to Predix: the application will be located on a mobile device. Of course, you can deploy your application to the PaaS and use it via browsers.
At the same time, you need to take care of Predix Mobile services that your application will communicate with. Next, we will focus on how to prepare Predix to serve your application requests.
Communicating with Predix Mobile services from an application
The implementation of the JS code for using Predix Mobile services is the same as you need in a RESTful application. You have to be able to make POST or GET requests. Find the sample code here.
Using Predix Mobile services
To make a valid request and get data from Predix services, you need to create a service instance and then bind it to your application.
To show what services are available for your application, run the following command:
As a result, you get a list similar to the one on the screenshot below.
cf create-service service_name plan my_instance command, create a service instance for your application:
cf create-service log-stash-1 free myapp-log-service
The next step is to bind the new service to your application using the
cf bind-service your_app_name service_instance_name command:
cf bind-service testhw myapp-log-service
To update your environment and put the changes into effect, run the following command:
cf restage app_name
Use the command bellow to show your configuration information about included services:
cf env app_name
For example, the
VCAP_SERVICES environment variable is shown on the image below.
The next step is to set up access to Predix services for making your requests.
Accessing Predix services
For this step, I use Predix tutorials as a guideline. You can find the details in Exploring Application Security: Create a Predix Service and set up a UAA ClientId.
Here is the section that you need.
My goal is to consecutively execute tasks from the following menu:
I’ll try to explain why this is necessary. Working with Predix Starter Kit, you create users who have access to services you bind to an application. In the Update Client menu, you paste
authority-token to add new authorities for accessing Predix services to your client.
Without this manipulation, a user can’t get data from the service even with a valid token. You can input a queue of tokens for several services. Mark them with quotes and separate with spaces.
Now, you are ready to do a request to fill an asset. Use the Predix form to make a test request.
The sample Predix documentation has a mistake: the locomotive endpoint in the URL should be plural—locomotives.
Note: The body of a POST request should be wrapped in square brackets.
I didn’t find any obstacles for creating cross-platform applications using Predix Mobile services during my experiment. However, when working with Predix, you do need to care about managing Predix services and binding them to your application.
- Deploying an ASP.NET Application to GE Predix
- Predix GA: GE Is Working on Security, Mobile Services, and Automating Ops
- GE Digital Exec Talks Open Predix—Based on Cloud Foundry
- GE Software Getting 2,000x Performance Increase with Cloud Foundry
For the next parts of this series, subscribe to our blog or follow @altoros.