In this Code Pattern we will show how to publish IOT Asset Data from external sources (Maximo) into the Watson IOT Analytics service. The data will allow us to then leverage Maximo Asset Monitor to observe individual building energy consumption and compare the performance of different buildings. The monitoring dashboards allow us to visualize energy consumption trends over time. This HTTP preload function could easily be modified to integrate to other IOT Platforms or data sources to allow you to quickly monitor your assets.
When the reader has completed this Code Pattern, they will understand how to:
- Understand how this Python function can load data into Watson IOT Platform Analytics from any REST Service
- Build a dashboard using Maximo Asset Monitor to monitor, visualize, and analyze IOT asset data from external sources
- Deploy, schedule and run these Python Functions in Watson IOT Platform Analytics to retrieve data from Maximo every 5 minutes.
The intended audience for this Code Pattern is application developers and other stakeholders who wish to utilize the power of Maximo Asset Monitor to quickly and effectively monitor any asset to ensure availability, utilization and efficiency.
-
Watson IOT Platform Analytics. This is a SaaS offering that allows you to register devices, collect IOT Data and build IOT applications. This add-on service extends "Watson IoT Platform" to include Maximo Asset Monitor. Sign up for an account here
-
Maximo. An IBM SAAS offering that allows you to register and manage assets. Sign up for a free trial here
-
HTTPPreload Python functions that allow you to collect IOT asset and sensor data from other IOT Platforms or data sources that can then be used to quickly monitor your assets in Watson IOT Platform Analytics.
- Setup your Python development environment
- Create an Entity Type in Watson IOT Platform
- Deploy function
- Schedule the function to collect asset data
- Create a Monitoring Dashboard to manage the asset
- View the Monitoring Dashboard with Building Energy Consumption
- An account on IBM Marketplace that has access to Watson IOT Platform Analytics and Maximo Asset Monitor. This service can be provisioned here
Follow these steps to setup and run this Code Pattern.
- Setup your Python development environment
- Create an entity type
- Deploy Function
- Import data to source
- View Dashboard
- Update Function
Mac comes with Python v2.7.9 recommend using Python v3.6.5 for using DB2. Launch Terminal
Install Brew, which is a package manager for Mac OS
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Install Python
brew install python3
Verify version of Python is above v3
python --version
Launch Terminal
Install "pip". (Python Package Installer):
sudo easy_install pip
Install virtual environment to keep dependencies separate from other projects
sudo pip install virtualenv
Create a virtual environment
python3 -m venv env
Enter your Virtual Environment directory
cd env
Activate your virtual environment
source bin/activate
The result in Terminal should be something like:
(env) My-Mac: myuserid$
Clone this repository
git clone git@github.com:IBM/watson-analytics-dashboard.git
cd watson-analytics-dashboard
Install dependencies
# Prereqs
pip install numpy
pip install sqlalchemy pandas ibm_db_sa urllib3 requests lxml sklearn ibm_db python-dotenv future
# Watson IOT Functions
pip install git+https://github.com/ibm-watson-iot/functions.git@production --upgrade
pip install -r requirements.txt
- Set PYTHONPATH to your project directory:
export PYTHONPATH="<root_project_directory>"
Copy template.env and modify it to reflect your Maximo Credentials.
cp ./custom/template.env ./custom/.env
Copy your Watson IOT Platform Service credentials into a credentials.json
file
Navigate to your Watson IOT Platform Analytics service
https://dashboard-us.connectedproducts.internetofthings.ibmcloud.com/preauth?tenantid=
Explore > Usage > Watson IOT Platform Analytics > Copy to clipboard
If you've created a custom fork of this repo, modify your .custom/functions.py to set your PACKAGE_URL as the forked Github repository:
PACKAGE_URL = 'git+https://github.com/kkbankol-ibm/watson-analytics-dashboard@'
# Change the class name if someone else has already published a function with the same name in your tenant function catalog.
class MaximoAssetHTTPPreload(BasePreload):
- Invoke local_test_of_function.py. This script will create a "Buildings" Entity Type and execute the MaximoAssetHTTPPreload function to pull data from Maximo at a given interval:
python local_test_of_function.py
Next, we'll add our custom function to our newly created entity. This will enable the function to run every 5 minutes and pull the latest meter readings. Navigate to the "Add Data view", and select the MaximoAssetHTTPPreload function. We can get to this form by the following
Explore > Entity Types > Buildings > Add Data
Set values/credentials for your Maximo instance.
URL = <maximo_url>
usernam = <username>
password = <password>
request = GET (select from drop down)
Here, we'll show how to add IoT data to a data source (Maximo). In this example, we'll use a Maximo instance. We'll begin by defining an "Asset Template". This will allow us to quickly generate multiple "Assets", which will represent buildings in this case. Access this form by searching for "Asset Templates" in the "Find Navigation Item" textbox in the upper left corner.
Each Asset can have multiple associated "Meters", which are used to track sensor readings over time. We'll add a "Temperature" meter and a "Energy" meter to our template.
Now that we have our asset template and associated meters defined, we can create a few building instances. We'll do this by clicking "Generate Building Assets". Provide a quantity and click "Ok".
After the building assets have been created, we can then look them up by clicking on "Assets" in the upper left menu. In the upper left "Find Asset" form, enter the number of one of the newly created assets.
Once the asset page loads, we can add data to the asset, select "Enter Meter Readings" in the lower left-hand menu, under the "More Actions" section. Provide values for the meters. In this example, be sure to add "temperature" values
Confirm the meter values have be saved by clicking "Manage Meter Reading History"
Finally, we can view our dashboards by clicking the "Monitor" button on the left hand menu, and then selecting your newly created entity (maximoBuildings)
Next, select the default summary dashboard
This will show an overview of instance data for all registered entities.
If you're interested in pulling data from additional / alternative data sources, you'll need to make a few changes to the custom/functions.py
file, which drives the IoT Analytics logic.
In our case, we first added methods to query the Maximo api
def getBuildings (self ):
q_endpoint = self.url + "/maximo/oslc/os/mxasset?oslc.select=assetid&oslc.where=assettag=" + "BUILDING"
headers = { "maxauth": self.token }
res = requests.get(q_endpoint, headers=headers)
return buildings
def getMeters (self, asset_id = None):
# hardcoding id for test TODO
asset_id = "2112"
q_endpoint = self.url + "/maximo/oslc/os/mxasset?oslc.select=assetmeter&oslc.where=assetnum=" + asset_id
headers = { "maxauth": self.token }
res = requests.get(q_endpoint, headers=headers)
meters = []
try:
meters = res.json()["rdfs:member"][0]["spi:assetmeter"]
print(str(len(meters)) + " meters found")
except:
print("no meters found")
pass
return meters
These methods query the Maximo OSLC api to receive all buildings and meters that are associated with an Asset derived from the "Building" template
Next, we added these custom methods to the main execute
method. The result of each method is then loaded into a response_data
dictionary as a numpy array.
buildings = self.getBuildings()
response_data['building'] = np.array(buildings)
..
..
meterValues = self.getMeters()
response_data['temperature'] = np.array(meterValues)
Finally, commit and push these changes to git, and rerun the local_test_of_function.py
script to register the function changes
git add ./custom/functions.py
git commit -m "my function changes"
git push origin master
-
Watson IOT Platform Code Patterns: Enjoyed this Code Pattern? Check out our other Watson IOT Platform Code Patterns.
-
Knowledge Center:Understand how this Python function can load data into Watson IOT Platform Analytics
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.