简体   繁体   English

简单设备发现和Web服务

[英]Simple Device Discovery and Web Services

I have a custom embedded hardware device running Linux controlled by a Python code. 我有一个由Python代码控制的运行Linux的自定义嵌入式硬件设备。 I'd like to create an Android client that will automatically find any of my devices on the local network, configure the devices, and display data from them. 我想创建一个Android客户端,该客户端将自动在本地网络上找到我的任何设备,配置设备并显示其中的数据。

I'd like to keep my implementation as simple as possible and leverage as much open source software possible for a quick implementation (with a strong preference towards actively maintained/support code). 我想使我的实现尽可能简单,并尽可能多地利用开源软件来实现快速实现(强烈倾向于积极维护/支持代码)。

My research so far has led me to favor a UPnP implementation, using SSDP to find my devices and letting the UPnP communicate via SOAP between my Android client and Python-controlled Linux device. 到目前为止,我的研究使我更喜欢UPnP实现,它使用SSDP查找我的设备,并让UPnP通过SOAP在我的Android客户端和Python控制的Linux设备之间进行通信。

  1. Is UPnP a good choice for this use case (I'm not a traditional UPNP device)? UPnP是否适合该用例(我不是传统的UPNP设备)? Or are there other standards-based approaches I should consider? 还是我应该考虑其他基于标准的方法?
  2. Assuming UPnP is reasonable: 假设UPnP是合理的:
    • (a) What are reasonable libraries to use on Android and in my Python/Linux device? (a)在Android和Python / Linux设备上可以使用哪些合理的库?
    • (b) Should I implement a custom UPNP "device" or should I try to shoehorn my solution into looking like a MediaServer? (b)我应该实现自定义的UPNP“设备”还是应该尝试将解决方案看起来像MediaServer?

Currently I'm attempting the implementation using Cling on the Android side and Coherence on the Python side, neither of which have been as straightforward as I would have hoped, which makes me wonder if I'm taking a smart approach. 目前,我正在尝试使用Android方面的Cling和Python方面的Coherence来实现,这两者都没有我希望的那么简单,这让我想知道我是否正在采用一种聪明的方法。

There's nothing wrong with using UPnP for this. 为此使用UPnP并没有错。 There's two questions here -- related but still independent: 这里有两个问题-相关但仍然独立:

  • How do you discover services? 您如何发现服务? SSDP is a valid technology but so is zeroconf: I'm not aware of an Android implementation but I assume one would exist. SSDP是一种有效的技术,但zeroconf也是一种技术:我不知道Android的实现,但我认为会存在。
  • How do you expose your API once the uri is found? 找到uri后,如何公开您的API? UPnP is a bit old school by now but works fine and if you use a decent library it's easy yet quite powerful. UPnP现在有点老了,但是效果很好,如果您使用不错的库,它既简单又强大。 Depending on your needs you could go with something like a normal REST webservice as well, or use SOAP without bothering with UPnP. 根据您的需求,您也可以使用普通的REST Web服务之类的东西,或者使用SOAP而不必担心UPnP。

Whether the questions really are unrelated depends on the libraries you use -- I have no idea if eg Cling lets you use just SSDP for a non-UPnP use case. 问题是否真的不相关取决于您使用的库-我不知道例如Cling是否允许您仅将SSDP用于非UPSnP用例。

  1. For the UPnP questions: 对于UPnP问题:

    • (a) I'm not very familiar with the Android side but for linux UPnP I would suggest GUPnP (I'm biased though, as I'm involved in its development): it's a stable and well tested library. (a)我对Android方面不是很熟悉,但是对于linux UPnP,我建议使用GUPnP (尽管我有偏见,因为我参与了它的开发):它是一个稳定且经过良好测试的库。 Python bindings aren't as well documented as they should be but they exist: from gi.repository import GUPnP . Python绑定没有得到应有的详细记录,但是存在: from gi.repository import GUPnP GUPnP also let's you do just SSDP if you want: see the GSSDP library. 如果需要,GUPnP也让您只做SSDP:请参阅GSSDP库。

    • (b) Definitely custom device if you can't find a good existing match, that's what UPnP was designed for. (b)如果您找不到合适的现有设备,则可以使用绝对定制的设备,这就是UPnP的目的。 In the GUPnP case you would write the device and service descriptions (in xml, see examples in the source) and load them with a RootDevice . 在GUPnP的情况下,您将编写设备和服务描述(在xml中,请参阅源代码中的示例),并使用RootDevice加载它们。 That takes care of device/service discovery and hosting the description docs. 这样可以处理设备/服务发现并托管描述文档。 Then you'd just need to implement the actions you have in your service description. 然后,您只需要实施服务描述中的操作即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM