面向python的ibm物联网云
ibmiotc的Python项目详细描述
用于python的ibm物联网云
==
platform
--
-`python 2.7<;https://www.python.org/download/releases/2.7>;``ependencies
----
-`paho mqtt<;http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.python.git/>;`\uuuxbr/>-`iso8601<;https://bitbucket.org/micktwomey/pyiso8601/>;`\uxbr/>
->安装
----
可以下载
最新版本并使用pip从文件安装的功能。
:
--
iotc
文档
----
>应用程序客户端
~~~~~~~~~~~~~~~~~~~~~~~~
constructor
^^^^^^^^^^^^^^^^
客户端构造函数接受一个选项dict,其中包含:\*org-your
organization id\*id-应用程序在
器官中的唯一idization\*authmethod-身份验证方法(当前支持的authmethod的唯一值是"api key")\*authkey-api key
(如果authmethod是"apikey",则为必需)\*authtoken-api key token
(如果authmethod是"apikey",则为必需)
代码::python
import ibmiotc.application
try:
options={"org":organization,"id":appid,"auth method":authmethod,"auth key":authkey,"auth token":authttoken}
client=ibmiotc.application.client(options)
除了E:
…
使用配置文件代码::python
import ibmiotc.application
尝试:
options=ibmiotc.application.parseconfigfile(configfilepath)
client=ibmiotc.application.client(options)
除了ibmiotc.connectionexception作为e:
…
le必须采用以下格式:
::
org=$org id
id=$myapplication
auth method=apikey
auth key=$key
auth token=$token
subscribing to device events
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
从所有连接的
设备。使用type、id和event参数控制订阅的范围。一个客户端可以支持多个订阅。
代码:python
client.subscribetodeviceevents()
代码::python
client.subscribetodeviceevents(devicetype=mydevicetype)
代码:python
client.subscribetodeviceevents(event=myevent)
代码::python
client.subscribetodeviceevents(devicetype=mydevicetype,deviceid=mydeviceid,event=myevent)
lient.subscribetodeviceevents(devicetype=myotherdevicetype,deviceid=myotherdeviceid,event=myevent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
要处理子选项接收到的事件,您需要注册一个事件回调方法。这些消息将作为事件类的
实例返回。event.device-string(唯一
标识组织中所有类型设备的设备
:math:`devicetype:`\deviceid)\*event.devicetype-s字符串\*
event.deviceid-string\*event.event-string\*event.format-string
\*event.data-dict\*event.timestamp-datetime
……代码::python
def myeventcallback(event):
打印从设备[%s]接收的%s事件'%s'(event.format,event.event,event.device,json.dumps(event.data))
…
client.eventcallback=myeventcallback
client.subscribetodeviceevents()
订阅设备状态
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
默认情况下,这将订阅所有连接的
设备的状态更新。使用type和id参数控制
订阅的范围。一个客户端可以支持多个订阅。
代码:python
client.subscribetodevicestatus()
代码:python
client.subscribetodevicestatus(devicetype=mydevicetype)
订阅两个不同设备的状态更新代码::python
client.subscribetodevicestatus(devicetype=mydevicetype,deviceid=mydeviceid)
lient.subscribetodevicestatus(devicetype=myotherdevicetype,deviceid=myotherdeviceid)
处理订阅接收到的状态更新,您需要注册事件回调方法。消息将作为状态类的
实例返回:
/>|\*status.time-datetime
\*status.action-string
\*status.connecttime-datetime
\*status.port-int
以下属性仅在操作为"disconnect"时设置:
\*status.writemsg-int\*status.readmsg-int\*status.reason-
string
|\*status.readbytes-int
\*status.writebytes-int
…代码::python
def mystatuscallback(状态):
如果status.action="disconnect":
打印%s-设备%s-%s(%s)"%(status.time.isoformat(),status.device,status.action,status.reason)
其他:
打印%s-%s-%s%(status.time.isoformat(),status.device,status.action)
…
client.statuscallback=mystatuscallback
client.subscribetodeviceststus()
publishing events"来自"devices
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
…代码::python
mydata={'name':'foo','cpu':60,'mem':50}
client.publishevent(mydevicetype,mydeviceid,"status",mydata)
代码::python
commanddata={rebootdelay':50}
client.publishcommand(mydevicetype,mydeviceid,"reboot",mydata)
==
platform
--
-`python 2.7<;https://www.python.org/download/releases/2.7>;``ependencies
----
-`paho mqtt<;http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.python.git/>;`\uuuxbr/>-`iso8601<;https://bitbucket.org/micktwomey/pyiso8601/>;`\uxbr/>
->安装
----
可以下载
最新版本并使用pip从文件安装的功能。
:
iotc
文档
----
>应用程序客户端
~~~~~~~~~~~~~~~~~~~~~~~~
constructor
^^^^^^^^^^^^^^^^
客户端构造函数接受一个选项dict,其中包含:\*org-your
organization id\*id-应用程序在
器官中的唯一idization\*authmethod-身份验证方法(当前支持的authmethod的唯一值是"api key")\*authkey-api key
(如果authmethod是"apikey",则为必需)\*authtoken-api key token
(如果authmethod是"apikey",则为必需)
代码::python
import ibmiotc.application
try:
options={"org":organization,"id":appid,"auth method":authmethod,"auth key":authkey,"auth token":authttoken}
client=ibmiotc.application.client(options)
除了E:
…
使用配置文件代码::python
import ibmiotc.application
尝试:
options=ibmiotc.application.parseconfigfile(configfilepath)
client=ibmiotc.application.client(options)
除了ibmiotc.connectionexception作为e:
…
le必须采用以下格式:
::
org=$org id
id=$myapplication
auth method=apikey
auth key=$key
auth token=$token
subscribing to device events
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
从所有连接的
设备。使用type、id和event参数控制订阅的范围。一个客户端可以支持多个订阅。
代码:python
client.subscribetodeviceevents()
代码::python
client.subscribetodeviceevents(devicetype=mydevicetype)
代码:python
client.subscribetodeviceevents(event=myevent)
代码::python
client.subscribetodeviceevents(devicetype=mydevicetype,deviceid=mydeviceid,event=myevent)
lient.subscribetodeviceevents(devicetype=myotherdevicetype,deviceid=myotherdeviceid,event=myevent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
要处理子选项接收到的事件,您需要注册一个事件回调方法。这些消息将作为事件类的
实例返回。event.device-string(唯一
标识组织中所有类型设备的设备
:math:`devicetype:`\deviceid)\*event.devicetype-s字符串\*
event.deviceid-string\*event.event-string\*event.format-string
\*event.data-dict\*event.timestamp-datetime
……代码::python
def myeventcallback(event):
打印从设备[%s]接收的%s事件'%s'(event.format,event.event,event.device,json.dumps(event.data))
…
client.eventcallback=myeventcallback
client.subscribetodeviceevents()
订阅设备状态
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
默认情况下,这将订阅所有连接的
设备的状态更新。使用type和id参数控制
订阅的范围。一个客户端可以支持多个订阅。
代码:python
client.subscribetodevicestatus()
代码:python
client.subscribetodevicestatus(devicetype=mydevicetype)
订阅两个不同设备的状态更新代码::python
client.subscribetodevicestatus(devicetype=mydevicetype,deviceid=mydeviceid)
lient.subscribetodevicestatus(devicetype=myotherdevicetype,deviceid=myotherdeviceid)
处理订阅接收到的状态更新,您需要注册事件回调方法。消息将作为状态类的
实例返回:
/>|\*status.time-datetime
\*status.action-string
\*status.connecttime-datetime
\*status.port-int
以下属性仅在操作为"disconnect"时设置:
\*status.writemsg-int\*status.readmsg-int\*status.reason-
string
|\*status.readbytes-int
\*status.writebytes-int
…代码::python
def mystatuscallback(状态):
如果status.action="disconnect":
打印%s-设备%s-%s(%s)"%(status.time.isoformat(),status.device,status.action,status.reason)
其他:
打印%s-%s-%s%(status.time.isoformat(),status.device,status.action)
…
client.statuscallback=mystatuscallback
client.subscribetodeviceststus()
publishing events"来自"devices
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
…代码::python
mydata={'name':'foo','cpu':60,'mem':50}
client.publishevent(mydevicetype,mydeviceid,"status",mydata)
代码::python
commanddata={rebootdelay':50}
client.publishcommand(mydevicetype,mydeviceid,"reboot",mydata)