Skip to content

Instantly share code, notes, and snippets.

@pi314
Last active January 25, 2016 08:03
Show Gist options
  • Save pi314/824d8cd328a6e75328c1 to your computer and use it in GitHub Desktop.
Save pi314/824d8cd328a6e75328c1 to your computer and use it in GitHub Desktop.
''' # my virtualenv settings, use with caution
$ virtualenv-2.7 .venv-openmtc-r4
$ source .venv-openmtc-r4/bin/activate
$ pip instal --upgrade openmtc-all-4.0.2.tar.gz
$ vim .venv-openmtc-r4/lib/python2.7/site-packages/etc/openmtc/gevent/config-gscl.json.dist
"file": "/var/log/gscl.log"
->
"file": "./gscl.log"
$ \python -m openmtc_gevent.gscl_main -f .venv-openmtc-r4/lib/python2.7/site-packages/etc/openmtc/gevent/config-gscl.json.dist
'''
''' # install openmtc package
sudo apt-get update
sudo apt-get install python-dev python-pip
sudo pip install --upgrade openmtc-all-4.0.2.tar.gz
sudo nano /etc/openmtc/gevent/config-gscl.json
sudo service openmtc-gscl start
curl localhost:4000/onem2m
'''
''' # install openmtc sdk package
sudo apt-get update
sudo apt-get install python-dev python-pip
sudo pip install --upgrade openmtc-sdk-4.0.2.tar.gz
'''
''' # check if both are installed
python -c "import openmtc; import openmtc_etsi; import openmtc_onem2m; import openmtc_app"
'''
from openmtc_etsi.model import Application
my_app = Application(appId='my_app', searchStrings=['key1', 'key2'])
print(my_app.values)
print(my_app.searchStrings)
from openmtc_etsi.scl import RetrieveRequestIndication, CreateRequestIndication
from openmtc_etsi.client.http import XIXClient
client = XIXClient('http://localhost:4000')
retrieve_req = RetrieveRequestIndication('/m2m')
response = client.send_request_indication(retrieve_req)
print(response)
print(response.status)
print(response.resource)
print(response.resource.values)
create_req = CreateRequestIndication('/m2m/applications/', my_app)
response2 = client.send_request_indication(create_req)
print(response2)
print(response2.status)
print(response2.resource)
print(my_app.values)
from openmtc_onem2m.transport import RequestMethod, OneM2MRequest
from openmtc_onem2m.model import AE
my_ae = AE(labels=['key2'])
print(my_ae)
print(my_ae.values)
retrieve_req = OneM2MRequest(RequestMethod.retrieve, 'onem2m')
from openmtc_onem2m.client.http import OneM2MHTTPClient
client = OneM2MHTTPClient('http://localhost:4000')
response = client.send_onem2m_request(retrieve_req)
print(response)
print(response.status_code)
create_req = OneM2MRequest(RequestMethod.create, 'onem2m?nm=my_ae', cn=my_ae)
response2 = client.send_onem2m_request(create_req)
print(response2)
print(response2.status_code)
retrieve_req2 = OneM2MRequest(RequestMethod.retrieve, 'onem2m/my_ae')
response3 = client.send_onem2m_request(retrieve_req2)
print(response3)
print(response3.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment