# monitoring_ui **Repository Path**: mirrors_ibm/monitoring_ui ## Basic Information - **Project Name**: monitoring_ui - **Description**: WARNING: This repository is no longer maintained ⚠️ This repository will not be updated. The repository will be kept available in read-only mode. Use React.js, Watson IoT Platform, and the Hyperledger Fabric Node SDK to interact with an IBM Blockchain service - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-23 - **Last Updated**: 2025-08-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Blockchain Monitoring UI In this Code Pattern, we'll use React.js, Watson IoT Platform, and the Hyperledger Fabric Node SDK to interact with an IBM Blockchain service. The resulting application provides a dynamically generated user interface to monitor assets as they traverse through a supply chain. This solution can be applicable for both physical assets (shipping containers, packages) and financial assets. Operators can use this Monitoring UI to perform actions on the blockchain, see the results of those actions, and query the state of each asset in the blockchain ledger. When the reader has completed this Code Pattern, they will understand how to: * Deploy a Hyperledger Blockchain network on IBM Cloud * Create and enroll an administrative client using the Hyperledger Node SDK * Deploy and Instantiate a smart contract to handle asset updates/queries * Create a schema describing the properties of an asset * Monitor and propose blockchain transactions via a UI * Integrate Watson IoT platform to directly receive asset updates from registered IoT devices via MQTT or HTTP  ## Flow 1. A request is submitted to Create, Read, Update, or Delete an asset from a blockchain ledger. This request may either be submitted manually by a user via the monitoring UI browser, or from a IoT device (NFC/barcode scanner, etc) publishing a MQTT message to the Watson IoT Platform. 2. Node Express backend formats CRUD request into a [jsonrpc](http://www.jsonrpc.org/specification#examples) object like below, and submits it to a Hyperledger peer as a transaction proposal. ```json { 'jsonrpc': '2.0', 'method': 'invoke', 'params': { 'type': 1, 'chaincodeID': { 'name': 'simple_contract' }, 'ctorMsg': { 'function': 'createAsset', 'args': '["assetID", {"carrier": "Port of Long Beach", "longitude":"33.754185", "latitude": "-118.216458", "temperature": "44 F"}]' }, 'secureContext': 'kkbankol@us.ibm.com' }, 'id': 5 } ``` 3. Peer uses an "endorsement" service to simulate the proposed transaction against the relevant smart contracts. This endorsement service is used to confirm that the transaction is possible given the current state of the ledger. Examples of invalid proposals might be creating an asset that already exists, querying the state of an asset that does not exist, etc. 4. If the simulation is successful, the proposal is then "signed" by the peer's endorser. 5. The signed transaction is forwarded to an ordering service, which executes the transactions and places the result into the ledger. 6. The Monitoring UI auto-refreshes to show the transaction result and updated ledger in the "Response Payloads" and "Blockchain" columns, respectively. ## Install Prerequisites: ### IBM Cloud CLI To interact with the hosted offerings, the IBM Cloud CLI will need to be installed beforehand. The latest CLI releases can be found at the link [here](https://console.bluemix.net/docs/cli/reference/ibmcloud/download_cli.html#download_install). An install script is maintained at the mentioned link, which can be executed with one of the following commands. ```bash # Mac OSX curl -fsSL https://clis.ng.bluemix.net/install/osx | sh # Linux curl -fsSL https://clis.ng.bluemix.net/install/linux | sh # Powershell iex(New-Object Net.WebClient).DownloadString('https://clis.ng.bluemix.net/install/powershell') ``` After installation is complete, confirm the CLI is working by printing the version like so ```bash ibmcloud -v ``` ### Node.js packages If expecting to run this application locally, please continue by installing [Node.js](https://nodejs.org/en/) runtime and NPM. Currently the Hyperledger Fabric SDK only appears to work with node v8.9.0+, but [is not yet supported](https://github.com/hyperledger/fabric-sdk-node#build-and-test) on node v9.0+. If your system requires newer versions of node for other projects, we'd suggest using [nvm](https://github.com/creationix/nvm) to easily switch between node versions. We did so with the following commands. ```bash curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash # Place next three lines in ~/.bash_profile export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion nvm install v8.9.0 nvm use 8.9.0 ``` To run the Monitoring UI locally, we'll need to install a few node libraries which are listed in our `package.json` file. - [React.js](https://reactjs.org/): Used to simplify the generation of front-end components - [MQTT](http://mqtt.org/): Client package to subscribe to Watson IoT Platform and handle incoming messages - [Hyperledger Fabric SDK](https://fabric-sdk-node.github.io/): Enables backend to connect to IBM Blockchain service Install the Monitoring UI node packages by running `npm install` in the project root directory and in the [react-backend](react-backend) directory. Both `python` and `build-essential` are required for these dependencies to install properly: ```bash npm install cd react-backend && npm install ``` Finally, compile the `bundle.js` file ```bash cd public npm run build ``` ## Included components * [Blockchain](https://cloud.ibm.com/catalog/services/blockchain) * [Watson IoT Platform](https://cloud.ibm.com/catalog/services/internet-of-things-platform) ## Featured technologies * [Hyperledger Fabric](https://hyperledger-fabric.readthedocs.io/en/release-1.1/) * [MQTT](http://mqtt.org/faq) * [npm](https://www.npmjs.com/) * [node.js](https://nodejs.org/en/) * [Hyperledger Node.js SDK](https://github.com/hyperledger/fabric-sdk-node) # Watch the Videos [](https://www.youtube.com/watch?v=Mw6924hCAIc) [](https://www.youtube.com/watch?v=DYvdN_p_Ldk) # Steps There are two methods we can use to deploy the application, either use the ``Deploy to IBM Cloud`` steps **OR** create the services and run locally. 1. [Clone repository](#1-clone-the-repository) 2. [Setup repository codebase locally](#2-deploy-application-locally) OR [Deploy to IBM Cloud](#2-deploy-application-to-ibm-cloud) 3. [Create Watson services with IBM Cloud](#3-create-services) 4. [Upload and Instantiate Chaincode](#4-upload-and-instantiate-chaincode) 5. [Start the Application](#5-run-the-application) 6. [Retrieve service credentials](#6-obtain-service-credentials) 7. [Configure and run the application](#7-ui-configuration) ## 1. Clone the repository Clone the `monitoring_ui` project locally. In a terminal, run: ```bash git clone https://github.com/IBM/monitoring_ui.git ``` ## 2. Deploy Application to IBM Cloud 1. To deploy the application to IBM Cloud, we'll need to leverage the IBM Cloud CLI. Ensure the cli is installed using the prerequisites section above, and then run the following command to deploy the application. ```bash ibmcloud cf push ``` 2. To see the app and services created and configured for this Code Pattern, use the IBM Cloud dashboard, or run `ibmcloud cf apps` and `ibmcloud cf services` in the terminal. The app should be named `monitoring-ui` with a unique suffix. ## 2. Deploy Application locally Install the Monitoring UI node packages by running `npm install` in the project root directory and in the [react-backend](react-backend) directory. Both `python` and `build-essential` are required for these dependencies to install properly: ```bash npm install cd react-backend && npm install ``` Finally, compile the `bundle.js` file ```bash cd public npm run build ``` ### Docker setup (optional) If you have Docker installed, you can install these dependencies in a virtual container instead. Run the application with the following commands, and then skip to [Step 5](#5-configure-credentials). ```bash docker build -t monitoring_ui . docker run -d -p 8081:8081 monitoring_ui ``` > NOTE: These steps are only needed when running locally instead of using the ``Deploy to IBM Cloud`` button. ## 3. Create Services Next, we'll need to deploy our service instances using the IBM Cloud dashboard. ### Watson IoT Platform We can start by deploying an instance of the Watson IoT Service. In this pattern, the primary role of this service is to offer an secure MQTT broker that'll receive asset updates from IoT devices. Our Monitoring UI subscribes to the MQTT broker and processes incoming messages with the fabric-client node SDK. First, log into the IBM Cloud dashboard at [https://cloud.ibm.com/](https://cloud.ibm.com/) and select the "Catalog" button in the upper right.  In the search bar type "IoT" and click the icon titled "Internet of Things Platform Starter".  Once this service is provisioned, we'll need to generate a set of credentials for connecting to the broker. We can do so by entering the IoT Platform dashboard, selecting "Devices" from the left hand menu, and then clicking the "Add Device" button.  Next, provide a device type and ID.  The next two steps (Device Information, Groups) can be skipped. In the "Security" tab, an Authentication token can be entered as long as it meets certain criteria (between 8 and 36 characters, contains mix of lowercase/uppercase letters, numbers, and symbols). Leave this field blank if you'd like for one to be generated instead.  Clicking the "Finish" button will generate a set of credentials that can be used to publish messages to the IoT Platform.  Now, MQTT publish commands can be made from a device in the following format: * Client ID: `d:${organization_id}:${device_type}:${device_id}` * Username: `use-token-auth` * Password: `${authentication_token}` * Endpoint: `${organization_id}.messaging.internetofthings.ibmcloud.com` To publish messages, a MQTT client will need to be installed on the IoT devices responsible for reading and sending asset updates. These clients are very lightweight, and are able to run on resource constrained devices such as Arduino, Raspberry Pi, CHIP, etc. Now that we have a valid set of credentials, we can use an MQTT client to send a sample command. There are a few clients available online, but for simplicity we'll use a node cli client. This particular client can be installed by running `npm install -g mqtt`, and is also used by the Monitoring UI backend. After exporting the MQTT credentials we can publish a json payload with the following commands: ```bash organization_id=agf5n9 device_type=assetTracker device_id=702f6460 username=use-token-auth password=YTiRp4jRdt4oyKTS3a mqtt_pub -i "d:${organization_id}:${device_type}:${device_id}" -u "${username}" -P "${password}" -h "${organization_id}.messaging.internetofthings.ibmcloud.com" -p 1883 -t 'iot-2/evt/deviceupdate/fmt/json' -m '{ "d" : { "fcn" : "updateAsset", "args" : "[{"carrier": "LBC Freight 647", "longitude":"34.754185", "latitude": "-119.214458", "temperature": "45 F"}]" } }' ``` And then we can see that message has been received by the IoT Platform dashboard by going back to the `Devices` menu, selecting our corresponding device, and then selecting `Recent Events`.  ### Blockchain We can continue on by deploying the IBM Blockchain service. This can be found by logging in to the IBM Cloud [dashboard](https://console.bluemix.net/), selecting the `Catalog` button, searching for "Blockchain", and clicking on the resulting icon. Or click this [*link*](https://console.bluemix.net/catalog/services/blockchain).  After selecting the blockchain icon, a form will be presented for configuring the service name, region, and pricing plan. The default values for these fields can be left as is. Also, be sure that the free pricing tier is selected, which is titled `Starter Membership Plan`. If you are using an IBM Cloud Lite account, this plan can be used for free for up to 30 days. After validating that the information in the form is correct, scroll down and click the `Create` button in the lower right corner. To begin the process of uploading the smart contracts, we can start by opening the Bluemix UI, selecting your provisioned Blockchain service, and accessing the blockchain network monitor by clicking ``Enter Monitor``