免费网络发现服务
cosmodiscover的Python项目详细描述
COSMO网络发现API
opensource cosmo网络发现api文档
这是用python编写的主要实现。有关其他实现,请参见Implemtations 有关api和协议的描述,请参见API Docs
安装
您可以使用pip和pypi安装它
python3 -m pip install cosmodiscovery
或者使用没有pypi的pip和github
python3 -m pip install git+https://github.com/SamHDev/CosmoDiscovery.git
使用量
导入libary
importcosmodiscoveryasdiscovery
发现服务器
server=discovery.DiscoveryServer()server.listen()
是的!就这样!
如果您想要自定义的scheme
或port
,您可以这样做:
server=discovery.DiscoveryServer(port=12892,scheme="_discovery._cosmo.home_device"))
使用发现回复发送自定义数据。cls
是一个DiscoveryRequestMessage
对象
@server.discovery_callbackdefon_msg(cls):cls.reply(data={})
发现客户端
创建这样的discoveryclient对象
server=discovery.DiscoveryServer()
或者使用参数so
client=discovery.DiscoveryClient(port=12892,scheme="_discovery._cosmo.home_device"))
创建一个您可以运行此功能
results=client.discovery()
此函数返回DiscoveryResult
对象的列表。如果列表为空,则找不到设备。
如果要在发现请求中添加要发送的自变量(如自定义数据)或缩短发现答复等待时间
你可以这样做:
results = discovery(timeout=1, data={})
再一次!就这么简单
更多文档
有关更多文档,请参见docs.md
由SamHDev为CosmoHome编写。根据License File