ledenet_api 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 574337eac1f731474460ee834ae7075f68884211
4
- data.tar.gz: 234f86496a5df7b8fb8e1ea483a033ea1891c4cb
3
+ metadata.gz: 8d957c5cc344a32f9a136953d6c250850eee2a49
4
+ data.tar.gz: e7d1aa4844be0c35a54cdcb50f38e9bb4ffec8f9
5
5
  SHA512:
6
- metadata.gz: 75cd7c937858687ec6b93bd0899092cc1367659a3febbe04b9eb9451523bc16ce4dbd19b3876c52a50e9080c24784a8dbc56cf2df6623749f63c7f6735f29b6f
7
- data.tar.gz: c9b7e98fd06694085000bcb0190aa30a93c13b4fc352e983eb15129fa3dbc4e4e731f9635504ffe1a49faa428ac3545ba01a7304fdeebfaa4224835a649fe10c
6
+ metadata.gz: 13ec8ea531321fbcf2ef004852680801522cf72c4b606ecb94d9003b2d1a3ead020811ae90cf73987d8514fd377c73097d3dca396399155342264211655783e2
7
+ data.tar.gz: 71f2af760c9487ec5d6e94917b35a60a24dbb219ee52dcc1b27b9bfa008741b88cb01fa75d2a6ef2d5b3e7d24b3c2ace5832203e98fa99d334869b8e0b4fa754
data/README.md CHANGED
@@ -1,2 +1,93 @@
1
1
  # ledenet_api
2
- An API for the LEDENET Magic UFO LED WiFi Controller
2
+ An API for the [LEDENET Magic UFO LED WiFi Controller](http://amzn.com/B00MDKOSN0)
3
+
4
+ ## What's this?
5
+ This RGB LED controller is a relatively cheap (~$30) alternative to something like the Phillips Hue RGB Strip + Hub, which can run you between $100 and $200.
6
+
7
+ However, it doesn't come with an open API, and doesn't integrate with smarthome hubs (SmartThings, etc.). I used a [packet capture app](https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture&hl=en) on my phone to reverse engineer how the official app communicated with the controller.
8
+
9
+ ## Installing
10
+
11
+ ledenet_api is available on [Rubygems](https://rubygems.org). You can install it with:
12
+
13
+ ```
14
+ $ gem install ledenet_api
15
+ ```
16
+
17
+ You can also add it to your Gemfile:
18
+
19
+ ```
20
+ gem 'ledenet_api'
21
+ ```
22
+
23
+ ## Using it
24
+
25
+ ### Device discovery
26
+
27
+ These devices implement a service discovery protocol, which allows you to find them on your network without digging for their IP address. To use it:
28
+
29
+ ```ruby
30
+ require 'ledenet_api'
31
+ devices = LEDENET.discover_devices
32
+ => [#<LEDENET::Device:0x007feccc0241d8 @ip="10.133.8.113", @hw_addr="XXXXXXXXXXXX", @model="HF-LPB100-ZJ200">]
33
+ devices.first.ip
34
+ => "10.133.8.113"
35
+ ```
36
+
37
+ ### API
38
+
39
+ To construct an API class, use the following:
40
+
41
+ ```ruby
42
+ api = LEDENET::Api.new('10.133.8.113')
43
+ ```
44
+
45
+ By default, each API call will open a new connection, and close it when it's finished. This is convenient if the API is being used inside of a long-running process (like a web server). If what you're doing is more short-lived, you can reuse the same connection:
46
+
47
+ ```ruby
48
+ api = LEDENET::Api.new('10.133.8.113', reuse_connection: true)
49
+ ```
50
+
51
+ By default, the API will re-try transient-looking failures three times. You can change this behavior with:
52
+
53
+ ```ruby
54
+ api = LEDENET::Api.new('10.133.8.113', reuse_connection: true, max_retries: 0)
55
+ ```
56
+
57
+ ### Status
58
+
59
+ To check if the controller is current on:
60
+
61
+ ```ruby
62
+ api.on?
63
+ => false
64
+ ```
65
+
66
+ To turn the controller on and off:
67
+
68
+ ```ruby
69
+ api.on
70
+ => true
71
+ api.off
72
+ => true
73
+ ```
74
+
75
+ ### Color
76
+
77
+ To get the current color setting (as an array of RGB values):
78
+
79
+ ```ruby
80
+ api.current_color
81
+ => [10, 10, 10]
82
+ ```
83
+
84
+ To set the color:
85
+
86
+ ```ruby
87
+ irb(main):016:0> api.update_color(255, 0, 255)
88
+ => true
89
+ ```
90
+
91
+ ### Warm White
92
+
93
+ This controller is also capable of controling Warm White (WW) LEDs. I didn't have a strip to test, but I'm pretty sure I found out how to control it. If this would be useful to you, please open an issue/pull request.
@@ -14,6 +14,11 @@ module LEDENET
14
14
  end
15
15
  end
16
16
 
17
+ DEFAULT_OPTIONS = {
18
+ expected_devices: 1,
19
+ timeout: 5
20
+ }
21
+
17
22
  # The WiFi controllers these things appear to use support a discovery protocol
18
23
  # roughly outlined here: http://www.usriot.com/Faq/49.html
19
24
  #
@@ -21,7 +26,9 @@ module LEDENET
21
26
  # containing IP address, hardware address, and model number. The model number
22
27
  # appears to correspond to the WiFi controller, and not the LED controller
23
28
  # itself.
24
- def self.discover_devices(expected_devices = 1, timeout = 5)
29
+ def self.discover_devices(options = {})
30
+ options = DEFAULT_OPTIONS.merge(options)
31
+
25
32
  send_addr = ['<broadcast>', 48899]
26
33
  send_socket = UDPSocket.new
27
34
  send_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
@@ -30,12 +37,12 @@ module LEDENET
30
37
  discovered_devices = []
31
38
 
32
39
  begin
33
- Timeout::timeout(timeout) do
40
+ Timeout::timeout(options[:timeout]) do
34
41
  while true
35
42
  data = send_socket.recv(1024)
36
43
  discovered_devices.push(LEDENET::Device.new(data))
37
44
 
38
- raise Timeout::Error if discovered_devices.count >= expected_devices
45
+ raise Timeout::Error if discovered_devices.count >= options[:expected_devices]
39
46
  end
40
47
  end
41
48
  rescue Timeout::Error
@@ -1,3 +1,3 @@
1
1
  module LEDENET
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ledenet_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins