ledenet_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/ledenet_api.gemspec +24 -0
- data/lib/ledenet/api.rb +73 -0
- data/lib/ledenet/device_discovery.rb +49 -0
- data/lib/ledenet/version.rb +3 -0
- data/lib/ledenet_api.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b9e08414e8a7138101e626e53506a9e101646cc
|
4
|
+
data.tar.gz: e763ee6fffb993e672db3d08ba631c2ad05de48d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1ebfcf2ab226033064a9e964c7c9c8cf23b234ccda03bdaff99d0f1a75ff9cb18070a7c876e44c229bbc3b380b05f6d34791d2f89cbc207f43bf757626f7855
|
7
|
+
data.tar.gz: dd2ce1ef6f07fa007a8c1081ef7121ea126bc04365c3e11f8c010cf0e68d269a7945fd928c8cf36dbb79bd78659d1ee56b91a361000cdb5f139df4f2d778e862
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ledenet_api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.3.0)
|
12
|
+
rspec-core (~> 3.3.0)
|
13
|
+
rspec-expectations (~> 3.3.0)
|
14
|
+
rspec-mocks (~> 3.3.0)
|
15
|
+
rspec-core (3.3.2)
|
16
|
+
rspec-support (~> 3.3.0)
|
17
|
+
rspec-expectations (3.3.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.3.0)
|
20
|
+
rspec-mocks (3.3.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.3.0)
|
23
|
+
rspec-support (3.3.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.10)
|
30
|
+
ledenet_api!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.10.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Christopher
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/ledenet_api.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
require "ledenet/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ledenet_api"
|
8
|
+
spec.version = LEDENET::VERSION
|
9
|
+
spec.authors = ["Christopher Mullins"]
|
10
|
+
spec.email = ["chris@sidoh.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{An API for the LEDENET Magic UFO LED WiFi Controller}
|
13
|
+
spec.homepage = "http://www.github.com/sidoh/ledenet_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/ledenet/api.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module LEDENET
|
2
|
+
class Api
|
3
|
+
API_PORT = 5577
|
4
|
+
|
5
|
+
def initialize(device_address)
|
6
|
+
@device_address = device_address
|
7
|
+
end
|
8
|
+
|
9
|
+
def on
|
10
|
+
send_bytes(0x71, 0x23, 0x0F, 0xA3)
|
11
|
+
end
|
12
|
+
|
13
|
+
def off
|
14
|
+
send_bytes(0x71, 0x24 ,0x0F, 0xA4)
|
15
|
+
end
|
16
|
+
|
17
|
+
def on?
|
18
|
+
(status.bytes[13] & 0x01) == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_color(r, g, b)
|
22
|
+
checksum = color_checksum(r, g, b)
|
23
|
+
|
24
|
+
send_bytes(0x31, r, g, b, 0xFF, 0, 0x0F, checksum)
|
25
|
+
end
|
26
|
+
|
27
|
+
def current_color
|
28
|
+
status.bytes[6, 3]
|
29
|
+
end
|
30
|
+
|
31
|
+
def reconnect!
|
32
|
+
create_socket
|
33
|
+
end
|
34
|
+
|
35
|
+
#private
|
36
|
+
def color_checksum(r, g, b)
|
37
|
+
(r + g + b + 0x3F) % 0x100
|
38
|
+
end
|
39
|
+
|
40
|
+
def status
|
41
|
+
begin
|
42
|
+
send_bytes(0x81, 0x8A, 0x8B, 0x96)
|
43
|
+
|
44
|
+
# Example response:
|
45
|
+
# [129, 4, 35, 97, 33, 9, 11, 22, 33, 255, 3, 0, 0, 119]
|
46
|
+
# R G B WW ^--- LSB indicates on/off
|
47
|
+
flush_response(14)
|
48
|
+
rescue Errno::EPIPE
|
49
|
+
reconnect!
|
50
|
+
retry
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def flush_response(msg_length)
|
55
|
+
@socket.recv(msg_length, Socket::MSG_WAITALL)
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_bytes(*b)
|
59
|
+
create_socket if @socket.nil?
|
60
|
+
|
61
|
+
begin
|
62
|
+
@socket.write(b.pack('c*'))
|
63
|
+
rescue Errno::EPIPE
|
64
|
+
reconnect!
|
65
|
+
retry
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_socket
|
70
|
+
@socket = TCPSocket.new(@device_address, API_PORT)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
module LEDENET
|
5
|
+
class Device
|
6
|
+
attr_reader :ip, :hw_addr, :model
|
7
|
+
|
8
|
+
def initialize(device_str)
|
9
|
+
parts = device_str.split(',')
|
10
|
+
|
11
|
+
@ip = parts[0]
|
12
|
+
@hw_addr = parts[1]
|
13
|
+
@model = parts[2]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# The WiFi controllers these things appear to use support a discovery protocol
|
18
|
+
# roughly outlined here: http://www.usriot.com/Faq/49.html
|
19
|
+
#
|
20
|
+
# A "password" is sent over broadcast port 48899. We can respect replies
|
21
|
+
# containing IP address, hardware address, and model number. The model number
|
22
|
+
# appears to correspond to the WiFi controller, and not the LED controller
|
23
|
+
# itself.
|
24
|
+
def self.discover_devices(expected_devices = 1, timeout = 5)
|
25
|
+
send_addr = ['<broadcast>', 48899]
|
26
|
+
send_socket = UDPSocket.new
|
27
|
+
send_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
28
|
+
send_socket.send('HF-A11ASSISTHREAD', 0, send_addr[0], send_addr[1])
|
29
|
+
|
30
|
+
discovered_devices = []
|
31
|
+
|
32
|
+
begin
|
33
|
+
Timeout::timeout(timeout) do
|
34
|
+
while true
|
35
|
+
data = send_socket.recv(1024)
|
36
|
+
discovered_devices.push(LEDENET::Device.new(data))
|
37
|
+
|
38
|
+
raise Timeout::Error if discovered_devices.count >= expected_devices
|
39
|
+
end
|
40
|
+
end
|
41
|
+
rescue Timeout::Error
|
42
|
+
# Expected
|
43
|
+
ensure
|
44
|
+
send_socket.close
|
45
|
+
end
|
46
|
+
|
47
|
+
discovered_devices
|
48
|
+
end
|
49
|
+
end
|
data/lib/ledenet_api.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ledenet_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Mullins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- chris@sidoh.org
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ledenet_api.gemspec
|
69
|
+
- lib/ledenet/api.rb
|
70
|
+
- lib/ledenet/device_discovery.rb
|
71
|
+
- lib/ledenet/version.rb
|
72
|
+
- lib/ledenet_api.rb
|
73
|
+
homepage: http://www.github.com/sidoh/ledenet_api
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.8
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: An API for the LEDENET Magic UFO LED WiFi Controller
|
97
|
+
test_files: []
|