MQTT is one of the most common messaging protocols used in the IoT world. Its lightweight structure and topic-based architecture enable fast and efficient message transmission, even over very low bandwidth. Watch the video above for an overview of the following exercise and to see how the MQTT protocol is used.
In this exercise, you will use the interoperability tools built into InterSystems IRIS for Health™ to construct a basic user portal that monitors live EKG readings from a set of remote patients. See how you can use a minimal amount of code to quickly take real-time data coming from an MQTT broker, then save and display it on a dashboard.
Make sure you have an instance of InterSystems IRIS ready to go. If you see your sandbox settings below, you are ready. Otherwise, login or register.
cd /home/project/shared
.git clone https://github.com/intersystems/Samples-MQTT-EKG-Devices
.set $Namespace = "INTEROP"
do $system.OBJ.Load("/home/project/shared/Samples-MQTT-EKG-Devices/Installer.cls","ck")
do ##class(App.Installer).InitializeLearningLab()
INTEROP
.
git clone https://github.com/intersystems/Samples-MQTT-EKG-Devices
.cd Samples-MQTT-EKG-Devices
.docker-compose up -d
.docker-compose exec iris iris session iris -U %SYS "##class(App.Installer).InitializeDocker()"
.INTEROP
namespace, navigate to Interoperability > List > Productions. Click New and complete the following fields:Click OK.
Enslib.MQTT.Message
. This is the message type that will be sent from our MQTT service as it receives heart rate data.Response
class to Demo.HeartRate
. This is a simple table class to which our MQTT message will be transformed. The code for this has already been written and is shown below./// Production response class. Target of data transformation /// that converts from MQTT topic and payload into a persistent object. Class Demo.HeartRate Extends (Ens.Response) { Property PatientID As %String; Property BPM As %Integer; // Initialize all HeartRate objects with a timestamp. Property TimeStamp As %DateTime [ InitialExpression = {$ZDATETIME($ZTIMESTAMP)} ]; }
start
activity, then open the Add Activity drop-down menu and add a transform
activity. The new activity displays in the business process with an arrow connecting it to start
. Complete the fields as follows:transform
activity, click DTL Editor to open the Data Transformation Builder, a tool that allows you to quickly transform between different object or message types.StringValue
and Topic
— from which the data transformation populates the PatientID field and the beats per minute, or BPM, field. The Topic field from an MQTT message resembles a directory path such as /acmeHospital/EKG/Patient-1
. In this case, the final level of the path is the patient identifier. The data transformation can populate the appropriate field in the HeartRate message by parsing the Topic string and using the final value, delimited by a forward slash (/).Piece
function with a forward slash (/) as the delimiter, and it navigates to the final value.transform
activity to the end
activity, then click Compile.Click OK. Then click the newly created From_EKG_MQTT
service. In the Settings tab on the right, enter the following information:
If you did not store your topic string, you can locate it by opening the shared/Samples-MQTT-EKG-Devices/App/app.html
file using Open With > Preview. Your topic string will be provided at the top of this page.
Click Apply.
Click OK.
Demo.MetricMQTT
is a simple business service that runs on a specific interval (in this case, 1) to compile readings and send them on to the built-in analytics dashboard utilities that come with InterSystems IRIS for Health. The business service is a custom-built class that inherits from the BusinessMetric
superclass, meaning that it takes all the functionality already built into that superclass and allows you to quickly configure it for your needs.Samples-MQTT-EKG-Devices/src/Demo/MetricMQTT.cls
in your online sandbox IDE.
Your production now subscribes to MQTT messages on a specific topic, converts them to a full Demo.HeartRate
record, and then sends a regular update into the dashboard. Next, you will create a dashboard to view this data.
Click OK.
Click Save at the top of the page.
You can now test your dashboard by opening the /shared/Samples-MQTT-EKG-Devices/App/app.html
file included in this GitHub repository in a browser. If you are using the IDE included with your learning lab, right-click this file, then select Open With > Preview.
Three simulated patients appear with flashing heart rates to indicate their beats per minute (BPM). You can adjust the BPM, and the changes will quickly show on the dashboard you created.
You can also click Add to add a new patient, and your dashboard will update within seconds to include the additional patient.
You have now successfully built a dashboard that monitors remote patient heart rates. For more information on using the MQTT utilities included with InterSystems IRIS for Health, visit InterSystems documentation.
To give you the best possible experience, this site uses cookies and by continuing to use the site you agree that we can save them on your device.