humble_rpi 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/humble_rpi.rb +63 -137
- data.tar.gz.sig +0 -0
- metadata +7 -68
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12bfe9a1e6e0b92814f02b33bfa4067c8ce5b64f
|
4
|
+
data.tar.gz: db7d231f2ff614a478adc7a117fe7388ee77ba22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9166aacd59e9bc7b29ff98e705380eeca3cf5b06a10fde43f9ae2fcd9409655c6de07b2069dec70dbd1599368e344c4047320cb4f44b190e26e6703865fe301
|
7
|
+
data.tar.gz: 2199950e22e505c3693d0d128f1f1e4fd886cafdfad34518fce053f460515b66b8e4407144fe97f24108660cdb10b4c56c1f77ab499e775446cc1b76baaa2ccd
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/humble_rpi.rb
CHANGED
@@ -2,169 +2,95 @@
|
|
2
2
|
|
3
3
|
# file: humble_rpi.rb
|
4
4
|
|
5
|
-
require 'rpi'
|
6
|
-
require 'chronic_duration'
|
7
5
|
require 'sps-pub'
|
8
|
-
require '
|
9
|
-
require 'websocket-eventmachine-client'
|
6
|
+
require 'sps-sub'
|
10
7
|
|
11
8
|
|
12
|
-
class
|
13
|
-
|
9
|
+
class DummyNotifier
|
10
|
+
|
11
|
+
def notice(message)
|
12
|
+
puts Time.now.to_s + ' - ' + message
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
class HumbleRPi
|
16
18
|
|
17
|
-
def initialize(
|
19
|
+
def initialize(device_name: 'rpi', sps_address: nil, sps_port: 59000, \
|
20
|
+
plugins: {})
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
motion_pin: nil,
|
24
|
-
button_pins: [],
|
25
|
-
sps_address: nil,
|
26
|
-
sps_port: '59000'
|
27
|
-
}
|
22
|
+
@device_name, @sps_address, @sps_port = device_name, sps_address, sps_port
|
23
|
+
|
24
|
+
@publisher, @subscriber = sps_address ? \
|
25
|
+
initialize_sps() : [DummyNotifier.new, nil]
|
28
26
|
|
29
|
-
@
|
30
|
-
|
31
|
-
|
27
|
+
@plugins = initialize_plugins(plugins || [])
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# triggered from a sps-sub callback
|
32
|
+
#
|
33
|
+
def ontopic(topic, msg)
|
34
|
+
|
35
|
+
component = topic[/\w+$/]
|
32
36
|
|
33
|
-
|
34
|
-
@led = RPi.new(led_pins).led if led_pins.any?
|
35
|
-
@ws = nil
|
37
|
+
method_name = "on_#{component}_message".to_sym
|
36
38
|
|
37
|
-
|
39
|
+
@plugins.each do |x|
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
[@opt[:motion_pin], @opt[:button_pins]].flatten.compact.each do |pin|
|
42
|
-
|
43
|
-
uexp = open("/sys/class/gpio/unexport", "w")
|
44
|
-
uexp.write(pin)
|
45
|
-
uexp.close
|
46
|
-
|
47
|
-
end
|
41
|
+
if x.respond_to? method_name then
|
42
|
+
x.method(method_name).call(msg)
|
48
43
|
end
|
44
|
+
|
49
45
|
end
|
50
|
-
end
|
46
|
+
end
|
51
47
|
|
52
|
-
def
|
48
|
+
def start()
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
rescue
|
60
|
-
puts 'humble_rpi: warning, could not publish SPS notice.'
|
50
|
+
@plugins.each do |x|
|
51
|
+
if x.respond_to? :on_start then
|
52
|
+
puts 'starting ' + x.inspect
|
53
|
+
Thread.new { x.on_start() }
|
54
|
+
end
|
61
55
|
end
|
62
|
-
end
|
63
|
-
|
64
|
-
protected
|
65
|
-
|
66
|
-
def button_detect()
|
67
|
-
|
68
|
-
send_message :info, 'button press detection activated'
|
69
|
-
|
70
|
-
topic = @opt[:device_name]
|
71
|
-
address, port = @opt[:sps_address], @opt[:sps_port]
|
72
|
-
|
73
|
-
hrpi = self
|
74
|
-
|
75
|
-
@opt[:button_pins].each.with_index do |button, i|
|
76
|
-
|
77
|
-
puts 'button %s on GPIO %s enabled ' % [i+1, button]
|
78
|
-
|
79
|
-
n = (i+1).to_s
|
80
|
-
|
81
|
-
PiPiper.watch :pin => button.to_i, :invert => true do |pin|
|
82
56
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
57
|
+
if @subscriber then
|
58
|
+
topic = "#{@device_name}/output/#"
|
59
|
+
@subscriber.subscribe topic: topic
|
60
|
+
else
|
61
|
+
loop while true
|
87
62
|
end
|
88
63
|
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def listener(&blk)
|
94
|
-
|
95
|
-
rpi = self
|
96
|
-
|
97
|
-
c = WebSocket::EventMachine::Client
|
98
|
-
|
99
|
-
Thread.new do
|
100
|
-
|
101
|
-
EM.run do
|
102
|
-
|
103
|
-
@ws = c.connect(uri: "ws://%s:%s" % [@opt[:sps_address], @opt[:sps_port]])
|
104
|
-
|
105
|
-
@ws.onopen do
|
106
|
-
puts "Client connected"
|
107
|
-
end
|
108
|
-
|
109
|
-
@ws.onmessage(&blk)
|
110
|
-
|
111
|
-
@ws.onclose do
|
112
|
-
puts "Client disconnected"
|
113
|
-
end
|
114
|
-
|
115
|
-
EventMachine.next_tick do
|
116
|
-
@ws.send "subscribe to topic: #{@opt[:device_name]}/output/#"
|
117
|
-
end
|
64
|
+
end
|
118
65
|
|
119
|
-
|
120
|
-
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def initialize_sps()
|
70
|
+
|
71
|
+
publisher = SPSPub.new address: @sps_address, port: @sps_port
|
72
|
+
publisher.notice @device_name + '/info: humble_rpi initialized'
|
73
|
+
subscriber = SPSSub.new address: @sps_address, port: @sps_port, callback: self
|
121
74
|
|
122
|
-
|
75
|
+
[publisher, subscriber]
|
123
76
|
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
alias led_listener listener
|
129
77
|
end
|
78
|
+
|
79
|
+
def initialize_plugins(plugins)
|
130
80
|
|
131
|
-
|
132
|
-
|
133
|
-
send_message :info, 'motion detection activated'
|
134
|
-
t1 = Time.now - ChronicDuration.parse('1 minute and 10 seconds')
|
135
|
-
topic = @opt[:device_name]
|
136
|
-
address, port = @opt[:sps_address], @opt[:sps_port]
|
137
|
-
|
138
|
-
hrpi = self
|
139
|
-
count = 0
|
140
|
-
|
141
|
-
after pin: @opt[:motion_pin].to_i, goes: :high do
|
81
|
+
@plugins = plugins.inject([]) do |r, plugin|
|
142
82
|
|
143
|
-
|
83
|
+
name, settings = plugin
|
84
|
+
return r if settings[:active] == false and !settings[:active]
|
144
85
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
t1 = Time.now
|
149
|
-
count = 0
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
153
|
-
PiPiper.wait
|
154
|
-
|
155
|
-
end
|
86
|
+
klass_name = 'HumbleRPiPlugin' + name.to_s
|
87
|
+
|
88
|
+
vars = {device_id: @device_name, notifier: @publisher}
|
156
89
|
|
90
|
+
r << Kernel.const_get(klass_name)\
|
91
|
+
.new(settings: settings, variables: vars)
|
157
92
|
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
if __FILE__ == $0 then
|
162
|
-
|
163
|
-
# example of an RPi running with 1 LED and 1 motion sensor
|
164
|
-
|
165
|
-
f = HumbleRPi.new device_name: 'fortina', led_pins: [17], sps_address: '192.168.4.170', motion_pin: '7'
|
166
|
-
|
167
|
-
sleep 3 # wait for the client to connect
|
168
|
-
f.motion_detect
|
93
|
+
end
|
94
|
+
end
|
169
95
|
|
170
96
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humble_rpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,68 +31,8 @@ cert_chain:
|
|
31
31
|
999CZL08Zqxa+1DKwhW/XqeiQ9eIZ+1fLAK+XbAKgv6ghNYEPtZLUFiD73uUbsKd
|
32
32
|
sBqeV1LF1yKYmA==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-
|
34
|
+
date: 2015-06-14 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rpi
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0.2'
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.2.0
|
46
|
-
type: :runtime
|
47
|
-
prerelease: false
|
48
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
50
|
-
- - "~>"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '0.2'
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.2.0
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: chronic_duration
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0.10'
|
63
|
-
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: 0.10.6
|
66
|
-
type: :runtime
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: !ruby/object:Gem::Requirement
|
69
|
-
requirements:
|
70
|
-
- - "~>"
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: '0.10'
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.10.6
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: websocket-eventmachine-client
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.1'
|
83
|
-
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 1.1.0
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- - "~>"
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '1.1'
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 1.1.0
|
96
36
|
- !ruby/object:Gem::Dependency
|
97
37
|
name: sps-pub
|
98
38
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +54,7 @@ dependencies:
|
|
114
54
|
- !ruby/object:Gem::Version
|
115
55
|
version: 0.4.0
|
116
56
|
- !ruby/object:Gem::Dependency
|
117
|
-
name:
|
57
|
+
name: sps-sub
|
118
58
|
requirement: !ruby/object:Gem::Requirement
|
119
59
|
requirements:
|
120
60
|
- - "~>"
|
@@ -122,7 +62,7 @@ dependencies:
|
|
122
62
|
version: '0.2'
|
123
63
|
- - ">="
|
124
64
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.2.
|
65
|
+
version: 0.2.0
|
126
66
|
type: :runtime
|
127
67
|
prerelease: false
|
128
68
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -132,7 +72,7 @@ dependencies:
|
|
132
72
|
version: '0.2'
|
133
73
|
- - ">="
|
134
74
|
- !ruby/object:Gem::Version
|
135
|
-
version: 0.2.
|
75
|
+
version: 0.2.0
|
136
76
|
description:
|
137
77
|
email: james@r0bertson.co.uk
|
138
78
|
executables: []
|
@@ -163,7 +103,6 @@ rubyforge_project:
|
|
163
103
|
rubygems_version: 2.4.6
|
164
104
|
signing_key:
|
165
105
|
specification_version: 4
|
166
|
-
summary:
|
167
|
-
|
168
|
-
broker'
|
106
|
+
summary: Controls components wired in through the Raspberry Pi's GPIO pins. see the
|
107
|
+
Humble_rpi plugins.
|
169
108
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|