OpenMTC/doc/training/onem2m-examples/onem2m-example-11b.py
aor-fokus 6cbb2e6144 Test debian stretch+python3 (#18)
* changes starting with python3 explicit

* removes python modules which are not available for python3

* exchanges fyzz query parsing with rdflib functionality

* fixes interop tests

* replaces reduce with for loop in nodb driver

* simple python2 -> python3 conversions

* adds changes for handling different string handling in python3

* test stretch building with travis

* installing python-setuptools in docker

* installing python-setuptools in docker

* changing python2 to python3 in docker makefiles

* changing python2 to python3 and some other test changes

* push docker only in master branche

* running version of openmtc

* fix some port problems

* porting path library completly now

* restoring travis.yml

* testing new travis.yml

* add sudo

* updating travis OS from trusty to xenial

* upgrade pip before

* show running docker logs

* show more logs

* for debugging

* showlogs of docker after failure

* testing new travis.yml

* finish travis.yml
2019-02-06 15:11:32 +01:00

44 lines
1.5 KiB
Python

# Example 11b: Updating a resource using OneM2MRequest Update
from openmtc_onem2m.model import AE
from openmtc_onem2m.client.http import OneM2MHTTPClient
from openmtc_onem2m.transport import OneM2MRequest
client = OneM2MHTTPClient("http://localhost:8000", False)
my_app = AE(App_ID="myApp",
labels=["keyword1", "keyword2"],
resourceName="MYAPP2",
requestReachability=False)
# Create the AE 'my_app' at the CSE
onem2m_request = OneM2MRequest("create", to="onem2m", ty=AE, pc=my_app)
promise = client.send_onem2m_request(onem2m_request)
onem2m_response = promise.get()
print(onem2m_response.content.labels)
#>>> [u'keyword1', u'keyword2']
# Retrieve the AE from the CSE and check the labels
path = "onem2m/" + onem2m_response.content.resourceName
onem2m_request = OneM2MRequest("retrieve", to=path)
promise = client.send_onem2m_request(onem2m_request)
onem2m_response = promise.get()
print(onem2m_response.content.labels)
#>>> [u'keyword1', u'keyword2']
# Update the changes labels in the remote resource
# Therefore a temporay AE object is needed
# This temporary AE object should ONLY contian the fields that need to be updated
tmp_app = AE(labels=["foo", "bar", "coffee"])
onem2m_request = OneM2MRequest("update", to=path, pc=tmp_app)
promise = client.send_onem2m_request(onem2m_request)
onem2m_response = promise.get()
print(onem2m_response.content.labels)
#>>> [u'foo', u'bar', u'coffee']
# Set the local AE to the retrieved content
my_app = None
my_app = onem2m_response.content
print(my_app.labels)
#>>> [u'foo', u'bar', u'coffee']