This is the continuation of the part 1 of this IBM Maximo with WATSON and IOT series.
So till now, we are able to open the node red flow and can see our sensor wired to the nodes.
There are two flows, the upper one is to simulate a temperature sensor in case you don’t want to use the simulated sensor from WATSON and you need random readings.
For this demo, we have already connected the IOT sensor to our lower flow and we will be using that.The extreme right window is showing the debug messages which are being passed through the flow.
You can change the temperature on your simulated sensor and point to the first green node(device data), you will soon start getting the debug messages.
These messages come from a predefined format which you specify in the dark green debug node.
Let me show you
Now this node sends out put to debug tab, on extreme right which I mentioned above and the output is the complete msg object.
* msg object is the actually message in JSON received from the sensor, you can play around the message payload and its contents using various other nodes from the node red editor.
So now we have a temperature function which is trying to get the temperature data out of the message JSON, as I mentioned above.
Here we have another variable called payload == actual message. payload .d. temp (Now actual message is of type JSON and here we are parsing it to go to the temperature value)
Next we have a switch node which will switch the paths based on the temperature value, same like java switch.
Now since we have redefined the payload value of msg, it currently carries a numerical temperature value( else payload itself will be of type JSON , as explained above)
So if temperature >40 take 2nd route else first.
Second route has our Maximo’s REST API call which will create an SR object in Maximo.
Keep deploying the changes on the node red by clicking the deploy button on top right, else your changes will not be visible.
Now as per danger node, we should see a message that – Temperature VALUE critical, which we can check from the debug tab.
By the way you can have multiple debug outputs, to make things clear you can disable other debug nodes by clicking on their node.
So till now you understood how node red is sending data from these wires based on different conditions.
Next we will trigger a REST call to Maximo if temperature is greater than 40.
Lets add a HTTP request node and assign the headers and payload for Maximo.
I am assuming you already have the payload ready for Maximo which will generate the SR request in case an event happens with the sensor( Real world scenario could be motor temperature is above the thresh hold and it needs a repair).
Now you should have a Maximo instance and you have the payload which will be sent to Maximo.
Usually payload will be the body which will go in the http post object.
You can get the http post body template from the Maximo object structures.
You need to generate schema xml for that object structure and it will show you the complete payload which will go to our HTTP request object.
For this demo I will be using the Maximo preview site and will generate the template from there.
Now remove the fields which are not required.I finally came up with some thing like this.
Code
=================================================================================
<?xml version="1.0" encoding="UTF-8"?>
<max:CreateMXSR xmlns:max="http://www.ibm.com/maximo" creationDateTime="2008-09-29T07:19:45" >
<max:MXSRSet>
<max:SR action="Create" >
<max:ASSETNUM changed="true">11200</max:ASSETNUM>
<max:AFFECTEDPERSON changed="true">MAXIMO</max:AFFECTEDPERSON>
<max:STATUS maxvalue="string" changed="false">NEW</max:STATUS>
<max:REPORTDATE changed="true">2017-04-06T11:24:06</max:REPORTDATE>
<max:REPORTEDBY changed="true">MAXIMO</max:REPORTEDBY>
</max:SR>
</max:MXSRSet>
</max:CreateMXSR>
=================================================================================
So these are the minimum fields required to create an SR and we need to go this to node red msg.payload object.
Lets see how
First create a function node and an http request node which will route the request, as shown below.
Both the nodes, Maximo SR Payload and the Maximo Create SR (HTTP REQUEST) node should look like this as shown below.
Make sure if Maximo has https , you need to select the SSL connection and uncheck the verify certificate option in the TLS configuration, click on pencil mark to edit.
Also make sure your payload looks like this and remove all new line characters and bring them in same line using notepad ++
Once every thing is done, try to raise the sensor temperature to 41 degrees and monitor the debug output.
Congrats, your SR is created. Please dispatch the agent to fix this, you might want to make a workflow to create a Work order also for this in Maximo.
Login to Maximo to check your SR
So this demo explained how you can use sensors and IBM Watson node red flow to create the SR and other objects in Maximo.
In next section of this series, we will see how we can integrate GPS data from a vehicle and integrate it with Maximo using WATSON.
Keep Reading !
Action Item: Share and Subscribe.
What URL should I put on http request?
ReplyDelete