Manage Device Changed Notifications
When the Alerts and Notifications Service is running it receives data about device changes from the core metadata. The Notifications Service can then send a notification to show the device has changed. An example of the notification is as follows:
Meatadata notice: {"deviceName":"Random-Boolean-Device","deviceServiceName":"device-virtual","actionType":"Device update","operatingState":"UP","adminState":"LOCKED"}
Configuring the Device Changed Notification.
When the PostDeviceChanges metadata configuration property is set to true
, the metadata service sends a DEVICE_CHANGED
notification with a label of metadata
to the Alerts and Notifications microservice when a device is changed.
The Device Changed Notifications are configured in the metadata microservice configuration properties, see Metadata Configuration Properties
The content sent in the device notification update can be changed as well as the description. To do this you need to use the consul
Start the consul and go to the path Key/Value > edgex > core > 2.0 > core-metadata > Notifications > Content
Subscribing to Device Changed Notifications
You can subscribe to the device changed notifications from the Alerts and Notifications microservice by creating a subscription with a category of DEVICE_CHANGED
and a label of metadata
To subscribe to the notifications using email you need to configure your email client, see Mail Server Configurable
To subscribe to notifications using ZeroMQ or MQTT, see the following examples:
For information on managing subscriptions using the Edge Xpert Manager, see Manage Subscriptions Using Edge Xpert Manager
Device Changed Notifcation Example
The examples require the Alerts and Notifications Service and the Virtual Device Service to be running. A suitable command to start the required Edge Xpert Services is as follows:
edgexpert up support-notifications device-virtual
Using Unencrypted Transport
In the following example, we are going to send the notification to MQTT using unencrypted transport. To create a subscription to the device changed notification, use the following command:
curl -X POST \
'http://localhost:59860/api/v2/subscription' \
-H 'Content-Type: application/json' \
-d '[
{
"apiVersion": "V2",
"subscription": {
"name": "DEVICE_CHANGED",
"channels": [{
"type": "MQTT",
"host": "test.mosquitto.org",
"port": 1883,
"publisher": "notification-service",
"topic": "iotech/notification",
"authmode": "none"
}
],
"categories": [
"DEVICE_CHANGED"
],
"labels": [
"metadata"
],
"receiver": "test-mqtt",
"adminState": "UNLOCKED"
}
}
]'
Creating the Notification
To create an example device changed notification you can change the adminState of the Random-Boolean-Device using the Xpert Manager.
Start the Xpert Manager using the command:
edgexpert up xpert-manager
Change the adminState of the Random-Boolean-Device from locked to unlocked by clicking the padlock icon in the Device list view as illustrated below:
Click the Lock button to confirm, as illustrated below:
Receiving the Notifications
These examples use the mosquitto_sub utility to demonstrate the receipt of notifications.
To see the notifications use the following command:
mosquitto_sub -h test.mosquitto.org -p 1883 -t iotech/notification
Now you should see a notification as follows:
Meatadata notice: {"deviceName":"Random-Boolean-Device","deviceServiceName":"device-virtual","actionType":"Device update","operatingState":"UP","adminState":"LOCKED"}