面向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)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何拆分字符串(基于各种分隔符),但不保留空格?   解析。Json格式的txt文件和knime中的java   java Spring rest api为什么在rest api调用的响应中更改了数据类型   升华文本3抛出java。lang.ClassNotFoundException,而记事本++不存在   java Android指纹扫描仪在尝试5次后停止工作?   java Android如何设置精确的重复报警?   java如何使用HTTPGET connect为access API输入用户名和密码   java当测试报告显示没有测试失败时,Gradle为什么说“有失败的测试”?   用Gson实现java获取响应   MapReduce程序中函数错误的java不可映射参数   java spring安全性不符合自动代理的条件   java GWT使用异步回调进行同步/阻塞调用   java奇怪的类数组问题无法在jsp中显示   如何在java中使用PrinterJob使用epl打印条形码   java如何在JTable中居中单元格   将Java Mockito测试转换为Kotlin   html Java正则表达式模式匹配到多个相同标记   testCompile中缺少java Gradle(Android)多项目依赖项   在输入提示后输入字符串时发生java FileNotFoundException