9.2.4 Create <semanticDescriptor>
The <semanticDescriptor> resource can be created by the entity that is creating the model or by a separate client entity, depending on the <accessControlPolicies> of the parent resource. This example shows the create <semanticDescriptor> for the Custom Model. The RDF triples that we used to semantically describe the washing machine were first converted to RDF/XML and then base64 encoded. The result of that encoding is used for the "dsp" attribute of the <semanticDescriptor>.
The following code is written using python and use the utilities available here [reference to ACME tutorial].
prefixes_io = '''@prefix saref: <https://saref.etsi.org/core/> .
@prefix s4bldg: <https://saref.etsi.org/saref4bldg/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sn: <http://www.XYZ.com/WashingMachines#XYZ_Cool> .
@prefix m2m: <https://git.onem2m.org/MAS/BaseOntology/raw/master/base_ontology.owl#> .
'''
smdBase = '''sn:WASH_XYZ_RESOURCE_ID a <http://www.XYZ.com/WashingMachines#XYZ_Cool> ;
rdfs:comment "Very cool Washing Machine" ;
saref:hasFunction sn:WASH_XYZ-MonitoringFunction, sn:WASH_XYZ-StartStopFunction ;
saref:hasManufacturer "XYZ" ;
saref:hasService sn:WASH_XYZ-MonitorService , sn:WASH_XYZ-SwitchOnService ;
saref:hasState sn:WASH_XYZ-WashingMachineStatus ;
s4bldg:isContainedIn sn:My_Bathroom ;
m2m:oneM2MTargetURI "RESOURCE_ID" ;
m2m:hasOperation sn:WASH_XYZ-SwitchOnService_RESOURCE_ID, sn:WASH_XYZ-StartStopFunction-ON_Command_RESOURCE_ID, sn:WASH_XYZ-StartStopFunction-OFF_Command_RESOURCE_ID, sn:WASH_XYZ-StartStopFunction-TOGGLE_Command_RESOURCE_ID,
sn:WASH_XYZ-MonitoringFunction-WashingMachineStatus_RESOURCE_ID .
'''
smdfull = prefixes_io + smdBase
g = Graph().parse(data=smdfull, format='n3')
smdxml = g.serialize(format='xml', indent=4)
targetURI = 'myWashingMachine'
payload = smdxml.replace("RESOURCE_ID", targetURI)
smd2b64 = smdEncode(payload)
CREATE(
'http://localhost:50000/oneM2M-semantics/' + targetURI,
# This is the Custom Washing Machine AE
# Request Headers
{
'X-M2M-Origin': originator1, # Set the originator
'X-M2M-RI': '123', # Request identifier
'X-M2M-RVI': '3', # Release verson indicator
'Accept': 'application/json', # Response shall be JSON
'Content-Type': 'application/json;ty=24' # Content is JSON, and represents an <semanticDescriptor> resource
},
# Request Body
{
'm2m:smd': {
'rn': 'smdCustomWasher',
'dcrp': 'application/rdf+xml:1', # the RDF triples use RDF/XML format;
'dsp': smd2b64 # the base64 encode triples
}
}
)
The resulting oneM2M primitive request and response using the HTTP protocol binding and JSON payload binding is shown below.
Sending request to http://localhost:50000/oneM2M-semantics/myWashingMachine
Headers
X-M2M-Origin: Cipe1
X-M2M-RI: 123
X-M2M-RVI: 3
Accept: application/json
Content-Type: application/json;ty=24
Body
{
"m2m:smd": {
"rn": "smdCustomWasher",
"dcrp": "application/rdf+xml:1",
"dsp": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHJkZjpSREYKICAgeG1sbnM6bTJtPSJodHRwczovL2dpdC5vbmVtMm0ub3JnL01BUy9CYXNlT250b2xvZ3kvcmF3L21hc3Rlci9iYXNlX29udG9sb2d5Lm93bCMiCiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIKICAgeG1sbnM6cmRmcz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC8wMS9yZGYtc2NoZW1hIyIKICAgeG1sbnM6czRibGRnPSJodHRwczovL3NhcmVmLmV0c2kub3JnL3NhcmVmNGJsZGcvIgogICB4bWxuczpzYXJlZj0iaHR0cHM6Ly9zYXJlZi5ldHNpLm9yZy9jb3JlLyIKPgogIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSJodHRwOi8vd3d3LlhZWi5jb20vV2FzaGluZ01hY2hpbmVzI1hZWl9Db29sV0FTSF9YWVpfbXlXYXNoaW5nT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lvbj4KPC9yZGY6UkRGPgo="
}
}
Response
MISSING TEXT
Body
{
"m2m:smd": {
"ct": "20220714T112657",
"et": "99991231T235959",
"lt": "20220714T112657",
"pi": "Cipe1",
"ri": "smd165779801715710114cse01"
}
}
The code above is repeated for each <semanticDescriptor> resource that is created. For this use case, there are six <semanticdescriptor> resources created. Three <semanticDescriptor> resources that describe the capabilities of the washing machine are identical except for the "RESOURCE_ID" token that is replaced with the appropriate value. The other three <semanticDescriptor> resources describe the API of the model and therefore have different values for the oneM2M baseOntology classes.