OpenMTC/doc/training/onem2m-examples/onem2m-example-12b.py

38 lines
1.5 KiB
Python
Raw Normal View History

2017-11-07 13:41:38 +00:00
# Example 12b: Forwarding
from openmtc_onem2m.client.http import OneM2MHTTPClient
from openmtc_onem2m.transport import OneM2MRequest
client = OneM2MHTTPClient("http://localhost:8000", False)
onem2m_request = OneM2MRequest("retrieve", to="onem2m")
onem2m_response = client.send_onem2m_request(onem2m_request).get()
2019-01-10 10:10:02 +00:00
print("---> Request to: http://localhost:8000" + "/" + onem2m_request.to)
print(onem2m_response.to)
2017-11-07 13:41:38 +00:00
#>>> onem2m
2019-01-10 10:10:02 +00:00
print(onem2m_response.response_status_code)
2017-11-07 13:41:38 +00:00
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
2019-01-10 10:10:02 +00:00
print(onem2m_response.content)
2017-11-07 13:41:38 +00:00
#>>> CSEBase(path='None', id='cb0')
onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m")
onem2m_response = client.send_onem2m_request(onem2m_request).get()
2019-01-10 10:10:02 +00:00
print("---> Request to: http://localhost:8000" + "/" + onem2m_request.to)
print(onem2m_response.to)
2017-11-07 13:41:38 +00:00
#>>> ~/mn-cse-1/onem2m
2019-01-10 10:10:02 +00:00
print(onem2m_response.response_status_code)
2017-11-07 13:41:38 +00:00
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
2019-01-10 10:10:02 +00:00
print(onem2m_response.content)
2017-11-07 13:41:38 +00:00
#>>> CSEBase(path='None', id='cb0')
client.port = 18000
onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m")
onem2m_response = client.send_onem2m_request(onem2m_request).get()
2019-01-10 10:10:02 +00:00
print("---> Request to: http://localhost:18000" + "/" + onem2m_request.to)
print(onem2m_response.to)
2017-11-07 13:41:38 +00:00
#>>> ~/mn-cse-1/onem2m
2019-01-10 10:10:02 +00:00
print(onem2m_response.response_status_code)
2017-11-07 13:41:38 +00:00
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
2019-01-10 10:10:02 +00:00
print(onem2m_response.content)
2017-11-07 13:41:38 +00:00
#>>> CSEBase(path='None', id='cb0')