This notebook demonstrates how to subscribe to notifications from resources.
The section does import necessary modules and configurations, and prepares the CSE for this notebook.
%run src/init.py subscriptions
The following requests creates a <subscription> resource for the Container resource.
CREATE ( # CREATE request
# Create subscription resource under the container
to = cseBaseName + '/StreetLight-AE-2/Light-Container-2',
# Request Parameters
originator = 'CstreetLight-AE-1', # Set the originator
requestIdentifier = '123', # Unique request identifier
releaseVersionIndicator = '3', # Release version indicator
resourceType = Type.Subscription, # Type of the resource: Subscription
# Request Body
primitiveContent =
{
'm2m:Subscription': {
'resourceName' : 'Subscription',
'notificationURI' : [ notificationURL ],
'notificationContentType' : 1,
'eventNotificationCriteria' : {
'notificationEventType': [ 1, 2, 3, 4 ]
}
}
}
)
Please check the Notification Server notebook (the one with the running Notification Server) to see the verification request.
When this requests returns with a 201 (Created) status code / 2001 oneM2M Response Status Code then the creation of the <subscription> resource as well as the verification request were successfull.
The request and response introduce new attributes:
Attribute | Short Name | Description |
---|---|---|
notificationURI | nu | The Notification URI specifies where to send verification and notification requests. This could be an entity, like an <AE>, or a direct URL. |
eventNotificationCriteria | enc | The configuration for the <subscription> that specifies when to send a event. |
notificationContentType | nct | The Notification Content Type attribute specifies the kind of content that should be sent in a notification initiated by this subscription. |
notificationEventType | net | A list of Notification Event Types indicates the reason when a notification is sent. |
notificationStatsEnable | nse | Record statistics per target how many notifications have been sent. |
notificationStatsInfo | nsi | A list of notification statistics per target. |
notification | sgn | A notification request structure. |
verificationRequest | vrq | Indicator that a notification is a so-called verification request. |
subscriptionReference | sur | The resource ID of the subscription for the notification request. |
creator | cr | The originator of a request that caused the notification. |
Value | Interpretation |
---|---|
1 | All. The whole resource |
2 | Only modified attributes |
3 | The resource's resource ID |
4 | The trigger payload in case of Triggers |
Value | Interpretation |
---|---|
1 | Update of Resource |
2 | Delete of Resource |
3 | Create of Direct Child Resource |
4 | Delete of Direct Child Resource |
5 | Retrieve of Container Resource With No Child Resource |
6 | Trigger Received For AE_Resource |
7 | Blocking Update |
We now have subscribed to a status change, i.e. whenever a child resource is added to the <container>. For example, when Streetlight-AE-2 receives a new command under this container, then a notification is raised by the <subscription> resource.
This is shown with the following request. To simplify he example the AE "StreetLight-AE-1" is the reques sender.
CREATE ( # CREATE request
# Add the <container> under the <AE>
to = cseBaseName + '/StreetLight-AE-2/Light-Container-2',
# Request Parameters
originator = 'CstreetLight-AE-1', # Set the originator
requestIdentifier = '123', # Unique request identifier
releaseVersionIndicator = '3', # Release version indicator
resourceType = Type.ContentInstance, # Type of the resource (ContentInstance)
# Request Body
primitiveContent =
{
'm2m:ContentInstance' : {
'contentInfo' : 'text/plain:0',
'content' : 'lights on'
}
}
)
Again, please check the Notification Server notebook to see the notification.
Any further creation of a <contentInstance> resource will cause a new notification to be sent.
The request and response introduce new attributes:
Attribute | Short Name | Description |
---|---|---|
notificationEvent | nev | The notification request contains a notification event. |
representation | rep | Representation for the notification as it was configured with the <subscription>'s notificationContentType attribute. |