Technical Blog Post
Abstract
Maximo, IoT and REST
Body
Maximo has a lot of integration abilities and one of them is the REST API. One of the really great thing about the REST API is that it is a very simple protocol that can be used to communicate with Internet of Things devices. It is compact and light weight and does not need much resources. There are many IoT devices to pick from but my personal favorite is the BeagleBone Black (BBB). It is a low cost credit card size computer and the best part is that it does not need much setup to communicate with Maximo. To try the example you only need a computer to connect your BBB to and an Ethernet cable to connect to the same network as the BBB.
Connect your BBB to your network with the Ethernet cable and hookup the USB cable to your computer, follow the instructions you got with your BBB to install drivers etc and you are ready to go.
On your computer hooked up to the BBB, open a browser and go to http://192.168.7.2:3000/ide.html. This will open up the Cloud9 development environment for Node.js. On your left, in the file system, create a new folder called Workspace under the cloud9 folder and then another folder Maximo under Workspace. Right click on Workspace and Add to Favorites. Right click on the Maximo folder and create a new file called MaxRest01.js.
Then copy and paste the following code into your MaxRest01.js file,
// MaxRest01.js // Use ordinary HTTP to communicate with Maximo var http = require('http'); // Our URL, replace IP and port for your system. var url = 'http://192.168.0.242:7001/maxrest/rest/mbo/locations?_lid=wilson&_lpwd=wilson&_compact=True&_format=json&_urs=False&description=100'; // We are looking for Locations MBOs, user password is wilson/wilson // Compact and format the response for Json // _urs=False to exclude row stamps. // description=100, look for descriptions that have 100 in the description. // Make a get request... http.get(url, function(res) { // This is our response, the body. var body = ''; // Fill up the body if more than one response. res.on('data', function(chunk) { body += chunk; }); // We got a full response, parse it. res.on('end', function() { // Get JSON object. var locationSet = JSON.parse(body); // Print for debug, uncomment if you want to see the full resonse. //var prettyJson = JSON.stringify(locationSet, null, ' '); //console.log("Got response:\n", prettyJson); // Flag start console.log("\nData from Maximo."); // Variables var location, description, type; // How many locations we got. console.log("Got ", locationSet.LOCATIONSMboSet.rsCount, " locations."); // Our locations. var locations = locationSet.LOCATIONSMboSet.LOCATIONS; // Loop through Locations for (locationData in locations) { // Set variables. location = locations[locationData].LOCATION; description = locations[locationData].DESCRIPTION; type = locations[locationData].TYPE; // Print it... console.log("location: " , location, ", ", description, ", ", type); } }); // Log any errors, hopefully none. }).on('error', function(e) { console.log("Got error: ", e); });
This is all the code needed to communicate with Maximo from the BBB, the most important part here is the URL, replace the IP address and port with your Maximo host IP. This URL will query the Maximo REST API and return 11 rows from a demo database, you might have to change the "description=100" part to get a result from your database. Try this URL in a browser and make sure you get a result before plugging it into the code. The URL also specifies _compact=True&_format=json, these parameters tell Maximo to return a compact JSON format which is easy for Node.js to use and process.
To run the code, change your working directory to the Maximo directory,
root@beaglebone:/var/lib/cloud9# cd Workspace/Maximo/
Then run the Node.js script,
root@beaglebone:/var/lib/cloud9/Workspace/Maximo# node MaxRest01.js Data from Maximo. Got 11 locations. location: AIR100 , Supply Duct Inlet- Conf. Room #100 , OPERATING location: BR430 , Condensate Return Pump- Centrifugal/100GPM/60FTHD , OPERATING location: BR450 , Feed Water Pump- Centrifugal/100GPM/60FTHD , OPERATING location: POLE100 , Electrical Service Pole #100 , OPERATING location: MH100 , Manhole Unit #100 , OPERATING location: SAN100 , Sanitary Pipe Segment #100 , OPERATING location: STORM100 , Storm Drain Segment #100 , OPERATING location: SEG100 , 12KV Line Segment #100 , OPERATING location: CONF100 , Conference Room #100 , OPERATING location: PT100 , PT100 , OPERATING location: BLK1000 , 1000 Block, Oak St - W560 , OPERATING root@beaglebone:/var/lib/cloud9/Workspace/Maximo#
The BBB is just one of many IoT devices that can be used to communicate with Maximo but the REST API is probably one of the easier way of doing it. This example requires minimal setup since the BBB has the Cloud9 development environment built in and is ready to go out of the box.
UID
ibm11131915