Giter Club home page Giter Club logo

simple_upnp's Introduction

Code Climate

simple_upnp

A few libraries already exist for working with Universal Plug and Play (UPnP) devices.

This library tries to provide a minimal implementation for discovery with a small amount of code and library dependencies.

For more info on uPnP, see: http://www.upnp-hacks.org/upnp.html

Installation

Add this line to your application's Gemfile:

gem 'simple_upnp'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_upnp

Usage

You may either:

  • search for a configurable number of seconds and return all unique devices that have responded.
  • attempt to find a specific device and exit early once found

The following example shows search (which can be triggered with the included rake task: "rake simple_upnp:search"):

include_location_details = true
devices = SimpleUpnp::Discovery.search()
devices.each do |device|
  puts 'Device Found: '
  puts device.to_json(include_location_details)
  puts ''
end

The following example shows find (which can be triggered with the included rake task: "rake simple_upnp:find_hue"):

include_location_details = true
hue_device = nil
SimpleUpnp::Discovery.find do |device|
  device_json = device.to_json(include_location_details)
  if device_json['root']
    if device_json['root']['device']
      if device_json['root']['device']['friendlyName']
        friendlyName = device_json['root']['device']['friendlyName']
        if friendlyName =~ /Philips hue/
          hue_device = device 
          break
        end
      end
    end
  end
end
if hue_device
  puts 'Device Found: '
  puts hue_device.to_json(include_location_details)
  puts ''
end

Search should produce output similar to the following:

Searching for devices...
Device Found: 
{:st=>"upnp:rootdevice", :server=>"Darwin 11.4.2 CyberLinkC/2.3 UPnP/1.0 DLNADOC/1.50", :usn=>"uuid:7DD8D98F-6577-582D-AF37-38B92EB830A4", :location=>"http://10.10.10.3:38400/description.xml", "root"=>{"specVersion"=>{"major"=>"1", "minor"=>"0"}, "device"=>{"deviceType"=>"urn:dmc-samsung-com:device:SyncServer:1", "friendlyName"=>"Adam’s MacBook Pro", "manufacturer"=>"Samsung-Electronics", "manufacturerURL"=>"http://www.samsung.com", "modelDescription"=>"Kies Sync Server", "modelName"=>"Kies Sync Server", "modelNumber"=>"1.0", "modelURL"=>"http://www.samsung.com", "UDN"=>"uuid:7DD8D98F-6577-582D-AF37-38B92EB830A4", "serviceList"=>{"service"=>{"serviceType"=>"urn:dmc-samsung-com:service:SyncManager:1", "serviceId"=>"urn:dmc-samsung-com:serviceId:SyncManager", "controlURL"=>"/KiesControll", "eventSubURL"=>"/KiesEventSub", "SCPDURL"=>"/KiesService_SCPD.xml"}}}, "URLBase"=>"http://10.10.10.3:38400", "@xmlns"=>"urn:schemas-upnp-org:device-1-0"}}

Device Found: 
{:st=>"upnp:rootdevice", :server=>"FreeRTOS/6.0.5, UPnP/1.0, IpBridge/0.1", :usn=>"uuid:2f402f80-da50-11e1-9b23-001788092b7e", :location=>"http://10.10.10.104:80/description.xml", "root"=>{"specVersion"=>{"major"=>"1", "minor"=>"0"}, "URLBase"=>"http://10.10.10.104:80/", "device"=>{"deviceType"=>"urn:schemas-upnp-org:device:Basic:1", "friendlyName"=>"Philips hue (10.10.10.104)", "manufacturer"=>"Royal Philips Electronics", "manufacturerURL"=>"http://www.philips.com", "modelDescription"=>"Philips hue Personal Wireless Lighting", "modelName"=>"Philips hue bridge 2012", "modelNumber"=>"929000242503", "modelURL"=>"http://www.meethue.com", "serialNumber"=>"001788542b7e", "UDN"=>"uuid:2f402f80-da50-11e1-9b23-001788092b7e", "serviceList"=>{"service"=>{"serviceType"=>"(null)", "serviceId"=>"(null)", "controlURL"=>"(null)", "eventSubURL"=>"(null)", "SCPDURL"=>"(null)"}}, "presentationURL"=>"index.html", "iconList"=>{"icon"=>[{"mimetype"=>"image/png", "height"=>"48", "width"=>"48", "depth"=>"24", "url"=>"hue_logo_0.png"}, {"mimetype"=>"image/png", "height"=>"120", "width"=>"120", "depth"=>"24", "url"=>"hue_logo_3.png"}]}}, "@xmlns"=>"urn:schemas-upnp-org:device-1-0"}}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

simple_upnp is released under the MIT license:

http://www.opensource.org/licenses/MIT

It makes use of the following libraries:

Nori - https://github.com/savonrb/nori

simple_upnp's People

Contributors

denniskuczynski avatar thathurleyguy avatar burgestrand avatar

Stargazers

JP Hastings-Spital avatar goldbook avatar Junichiro Takagi avatar Aren Patel avatar Tom Hornos avatar Pedro Giménez avatar

Watchers

James Cloos avatar deknos avatar  avatar

simple_upnp's Issues

missing runtime dependency: nokogiri

Hi again!

It appears Nori can use either Nokogiri or REXML, but if nothing else is being said it will default to Nokogiri. Since it’s not possible to pass in options to Nori.new when parsing the location XML, simple_upnp will always default to Nokogiri, making it a runtime dependency.

  1. either add nokogiri as runtime dependency of simple_upnp, and use the default.
  2. or switch to REXML by default (which is in stdlib)
  3. or allow users of simple_upnp to choose whichever they prefer, and default to rexml

I don’t really have a preference to either one! :)

Errno::EADDRINUSE: Address already in use - bind(2) for "" port 1900

I have no idea how no one has ever posted this issue.

I'm using a library which requires simple_upnp. When I attempt to use it, I receive the following error message:

Errno::EADDRINUSE: Address already in use - bind(2) for "" port 1900

Hoping that I could look at this library to rebind the port somewhere else, but it looks like it is hard coded. I know very little on UPnP, so I don't know if the port is standard or not.

I attempted to use this library to do the Discovery.search() suggested in the README and got the same error.

>> require 'simple_upnp'
=> true
>> include_location_details = true
=> true
>> devices = SimpleUpnp::Discovery.search()
Errno::EADDRINUSE: Address already in use - bind(2) for "" port 1900
    from /Users/bhardin/.rvm/gems/ruby-2.1.5/gems/simple_upnp-0.0.5/lib/simple_upnp/discovery.rb:43:in `bind'
    from /Users/bhardin/.rvm/gems/ruby-2.1.5/gems/simple_upnp-0.0.5/lib/simple_upnp/discovery.rb:43:in `open_socket'
    from /Users/bhardin/.rvm/gems/ruby-2.1.5/gems/simple_upnp-0.0.5/lib/simple_upnp/discovery.rb:15:in `search'
    from (irb):3
    from /Users/bhardin/.rvm/rubies/ruby-2.1.5/bin/irb:11:in `<main>'

Can anyone help?

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.