With the Peakboard Hub Online it’s easily possible to connect cloud apps and services to applications that run on the worker’s Workplace in a factory. That’s one of the main ideas behind connecting the boxes to the Hub. In this article we will discuss, how to use an Azure Logic App to build a simple workflow to call functions in a Peakboard app. The possibilities of this techniques are endless.
The Azure Logic App uses the regular API to communicate with the Hub. And Hub in turn has a secure connection through the firewall of the customer factory to the box. That makes it perfectly secure to bridge the gap between cloud services and apps and any kind of entity that resides directly in the highly sensitive area of production IT.
The Peakboard app and other requirements
In our example we use the Alarm app that we already discussed in the article about how to call a function by using the API. This app exposes a function called “SubmitAlarm” and just displays the alarm message in the screen for a given number of seconds (which is the second parameter for the function).
We want to use the Azure Logic App later to trigger that function on the box. The logic of the function is very simple.
The box we want to use is registered in the Peakboard Hub.
And also we need an API key with at least the scope “write:box” to allow a 3rd party caller to execute the function.
Build the Azure Logic App
Before we steps into the details of each step, how does our Logic work? We need three steps to call the function:
- Authenticate against the Hub API with our API key
- Parse the JSON string that is returned by the authentification
- Call the actualy API to execute the function
After having a created a new Logic App in the Azure portal, we add the first http call as shown in the screenshot. The endpoint GET “/auth/token” receives the API key within an additional header with key “apiKey”.
The actual access token is returned in the JSON string of the response body. To make the token available we use a “Parse JSON” block in the logic app. The schema that is used for parsing the JSON string can either by typed manually or just copied from this template.
For the actual alarm to be submitted we call the endpoint POST “/box/function”. The body of the request contains the JSON to trigger the right function on the right box with the right parameters:
Here’s how the call looks like in the design mode.
The additional header “Authorization” is a simple concatenate from the term “Bearer “ with the token that is extracted from the JSON in the previous parsing step.
Of course in our sample we don’t catch any kind of exceptions or other problems that might occur to make sure the example is easy to understand. In a real world application we must consider that authentification might go wrong or the box is not available to be called.
result
We can try out the app simply by running the Logic App manually. ALl workflow steps should have green check marks if no problems occur.
And the alarm is submitted to the box and displayed on the screen.