GithubHelp home page GithubHelp logo

rupnp's Introduction

GitHub last commit Crates.io

rupnp

An asynchronous library for finding UPnP control points, performing actions on them and reading their service descriptions. UPnP stand for Universal Plug and Play and is widely used for routers, WiFi-enabled speakers and media servers.

Spec: http://rupnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v2.0.pdf

Example usage:

The following code searches for devices that have a RenderingControl service and print their names along with their current volume.

use futures::prelude::*;
use std::time::Duration;
use rupnp::ssdp::{SearchTarget, URN};

const RENDERING_CONTROL: URN = URN::service("schemas-upnp-org", "RenderingControl", 1);

#[tokio::main]
async fn main() -> Result<(), rupnp::Error> {
    let search_target = SearchTarget::URN(RENDERING_CONTROL);
    let devices = rupnp::discover(&search_target, Duration::from_secs(3)).await?;
    pin_utils::pin_mut!(devices);

    while let Some(device) = devices.try_next().await? {
        let service = device
            .find_service(&RENDERING_CONTROL)
            .expect("searched for RenderingControl, got something else");

        let args = "<InstanceID>0</InstanceID><Channel>Master</Channel>";
        let response = service.action(device.url(), "GetVolume", args).await?;

        let volume = response.get("CurrentVolume").unwrap();

        println!("'{}' is at volume {}", device.friendly_name(), volume);
    }

    Ok(())
}

License

Licensed under either of

at your option.

Contribution

Please use rustfmt before any pull requests.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

rupnp's People

Contributors

dennisosrm avatar dheijl avatar jakobhellermann avatar liferooter avatar stanislav-omelchenko avatar tapghoul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rupnp's Issues

It is not possible to specify a TTL for the discover function

When broadcasting to discover new devices, it is useful to be able to specify a TTL, which is an UPnP feature that allows finding devices that are in more than one hop of distance from the host (e.g. a multi-router home network). This is related to this similar issue in the ssdp-client library.

Considering that the ssdp_client::search function now have the TTL option, the fix is as simple as exposing the TTL parameter to therupnp::discover function.

SCPD fails when an allowedValueRange maximum is an empty string

In trying to set up a system with a friend's router (so I am unable to rigorously test), I found that when parsing StateVariables when calling service.scpd(), I got this error: Invalid response: cannot parse integer from empty string

Turns out, in their WANIPConn1 service, the Uptime state variable had no maximum defined. Specifically:

<stateVariable sendEvents="no">
  <name>Uptime</name>
  <dataType>ui4</dataType>
  <defaultValue>0</defaultValue>
  <allowedValueRange>
    <minimum>0</minimum>
    <maximum/>
    <step>1</step>
  </allowedValueRange>
</stateVariable>

When parsing, maximum here causes the parsing to fail.

The specific router is a TP-Link TD-W9970, model number 4.0.
It also reproduces on the TP-Link Archer VR1600v (unknown model version)

I'm not sure how this would best be represented, but if informed how to I'm happy to do a PR myself.

The specific error location is in scpd::state_variable::range_from_xml() when parsing maximum by calling utils::parse_node_text().

Discovery fails if a device does not have a servicelist

When a device, like a Philips Hue bridge, has no services to advertise, the method devices.try_next() throws an unrecoverable error:

Error: XmlMissingElement("device", "serviceList")

aborting any further device discovery on the network, unless I am missing something?

Thanks for a very well designed library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.