humble_rpi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +3 -0
- data/lib/humble-rpi.rb +123 -0
- metadata +82 -0
- metadata.gz.sig +1 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6fa85ada8d13f9047d3c215ff70679242c8cf792
|
4
|
+
data.tar.gz: 3770d991cdd126994b9dc882d8eb1ef6974bd9ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da259b4e269b2c4d1458b39948aeabdc81736aede51b5354dc92ee78752972788907486dd5e7d48a9bcf2a8bc4398e40158444185d2194827a75927d1c269f77
|
7
|
+
data.tar.gz: 8957e8864211215f046de1b79b478eecd84dac3cd102688e6e14ade237bea2566778505b5342e29b8f7a6698436a562f4e6e3ce425f46bab05c1aeb84b8333b1
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
E;VIN6�sM��4�����H%�*Wj�<�͔?H��I���H~
|
data.tar.gz.sig
ADDED
data/lib/humble-rpi.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: humble_rpi.rb
|
4
|
+
|
5
|
+
require 'rpi'
|
6
|
+
require 'chronic_duration'
|
7
|
+
require 'websocket-eventmachine-client'
|
8
|
+
|
9
|
+
|
10
|
+
class HumbleRPi < RPi
|
11
|
+
include PiPiper
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
|
15
|
+
default_options = {
|
16
|
+
device_name: 'rpi',
|
17
|
+
led_pins: [],
|
18
|
+
motion_pin: nil,
|
19
|
+
sps_address: nil,
|
20
|
+
sps_port: '59000'
|
21
|
+
}
|
22
|
+
|
23
|
+
@opt = default_options.merge options
|
24
|
+
super @opt[:led_pins]
|
25
|
+
@ws, @rpi = nil, nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def led_listener(&blk)
|
29
|
+
@rpi = self
|
30
|
+
rpi = @rpi
|
31
|
+
|
32
|
+
c = WebSocket::EventMachine::Client
|
33
|
+
|
34
|
+
Thread.new do
|
35
|
+
|
36
|
+
EM.run do
|
37
|
+
|
38
|
+
@ws = c.connect(uri: "ws://%s:%s" % [@opt[:sps_address], @opt[:sps_port]])
|
39
|
+
|
40
|
+
ws.onopen do
|
41
|
+
puts "Client connected"
|
42
|
+
#@ws = ws
|
43
|
+
end
|
44
|
+
|
45
|
+
@ws.onmessage(&blk)
|
46
|
+
|
47
|
+
@ws.onclose do
|
48
|
+
puts "Client disconnected"
|
49
|
+
end
|
50
|
+
|
51
|
+
EventMachine.next_tick do
|
52
|
+
@ws.send "subscribe to topic: #{@opt[:device_name]}_led"
|
53
|
+
end
|
54
|
+
EventMachine.error_handler{ |e|
|
55
|
+
puts "Error raised during event loop: #{e.message}"
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def motion_detect()
|
66
|
+
|
67
|
+
t1 = Time.now
|
68
|
+
ws, opt = @ws, @opt
|
69
|
+
|
70
|
+
after pin: opt[:motion_pin].to_i, goes: :high do
|
71
|
+
|
72
|
+
#puts Time.now.to_s + ' : motion detected'
|
73
|
+
|
74
|
+
if Time.now > t1 + ChronicDuration.parse('1 minute') then
|
75
|
+
ws.send opt[:device_name] + ': motion detected'
|
76
|
+
t1 = Time.now
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
PiPiper.wait
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
if __FILE__ == $0 then
|
87
|
+
|
88
|
+
# example of an RPi running with 1 LED and 1 motion sensor
|
89
|
+
|
90
|
+
f = HumbleRPi.new device_name: 'fortina', led_pins: [17], sps_address: '192.168.4.170', motion_pin: '7'
|
91
|
+
rpi = f
|
92
|
+
|
93
|
+
onmessage = lambda do |msg,type|
|
94
|
+
|
95
|
+
puts 'message received'
|
96
|
+
|
97
|
+
topic, raw_message = msg.split(/\s*:\s*/,2)
|
98
|
+
r = raw_message.match(/(\d+)\s*(on|off|blink)\s*([\d\.]+)?/)
|
99
|
+
|
100
|
+
if r then
|
101
|
+
index, state, seconds = r.captures
|
102
|
+
elsif raw_message[/mpd|audio/] then
|
103
|
+
|
104
|
+
h = {'mpd play' => :on, 'mpd stop' => :off,
|
105
|
+
'audio on' => :on, 'audio off' => :off}
|
106
|
+
index, state = 0, h[raw_message]
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
# seconds should be nil unless state == blink
|
111
|
+
if seconds then
|
112
|
+
rpi.led[index.to_i].blink seconds.to_f
|
113
|
+
else
|
114
|
+
rpi.led[index.to_i].send(state.to_sym)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
f.led_listener &onmessage
|
120
|
+
sleep 3 # wait for the client to connect
|
121
|
+
f.motion_detect
|
122
|
+
|
123
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: humble_rpi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTEzMTEyNDIyNTA1MloXDTE0MTEyNDIyNTA1MlowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZ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K97Fz/NM76+KNaPEa6pYgH+JF/i/VxG6aln5EavRfNdLWM0pBirSt/kpw9jDToHo
|
32
|
+
YglbilVTUndGuw==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2013-11-24 00:00:00.000000000 Z
|
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'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
description:
|
51
|
+
email: james@r0bertson.co.uk
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- lib/humble-rpi.rb
|
57
|
+
homepage: https://github.com/jrobertson/humble_rpi
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.0.rc.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Designed for a Raspberry Pi which uses GPIO LEDs, 1 motion sensor and communicates
|
81
|
+
with a SimplePubSub message broker
|
82
|
+
test_files: []
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
a/D(t�,<���2rz��x�5��xj�jG�P��m�S��� ��������w5Ѭ@"������Xt}�7�ا�����nI'��#��24���pr�7YR�#�*M�(}'5C��|�@Eݳ;7e,`ӏ��eY%�چIOV��_&�4a+���t��A�nq��J����Ho+*A���Q��ah�����=�����}M&;?V�g2�ژ<ֳ!�O��6CM&\��* U��Zb��[F;i��O�^a�zN�'s��
|