设备配置单元python web配置程序
devicehive-webconfig的Python项目详细描述
设备配置单元Python Web配置器
这是的代理包 devicehive-python 它提供简单的web界面来配置连接。
安装
pip install devicehive-webconfig
使用量
基础知识
基于python httpserver的web界面并实现设备配置单元
分离螺纹连接。
它接受handler类作为参数,就像原始的devicehive类一样。
这个存储库中扩展{em1}$handler类的唯一区别
必须使用。
服务器可以在非阻塞模式下运行,因此主线程可以
使用。
示例:
importtimeimportjsonfromdevicehive_webconfigimportServer,HandlerclassExampleHandler(Handler):_device=Nonedefhandle_connect(self):self._device=self.api.put_device(self._device_id)super(ExampleHandler,self).handle_connect()defsend(self,data):self._device.send_notification(data)if__name__=='__main__':server=Server(ExampleHandler,is_blocking=False)server.start()print('Go to http://127.0.0.1:8000/ and configure your connection.')whilenotserver.dh_status.connected:# Wait till DH connection is readytime.sleep(.001)foriinrange(10):server.deviceHive.handler.send('notification #{}'.format(i))
附加的handler参数可以作为args和kwargs
传递高级
这个库设计得很容易扩展。其他路线, 可以添加控制器、模板和静态文件。有一个 example这说明了如何做到这一点。