ipwebcam_sensor2020 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 +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ipwebcam_sensor2020.rb +140 -0
- metadata +71 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4dc54c2cfa8fd7a6f4c4fd0be0bdfe50134e99b10d1cea6858cfa9fe764f5f81
|
4
|
+
data.tar.gz: e838e70bcdf07181ec2f41ca71640997f95896b53adcb5fa2c2d289be78a1b82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bb1a43d2c4c6e96beb639303a711562ba17034881681f8d882a3651d1e844a9c917cda0d3f6874c3c1944243c46ddf7d44ae05955bfb42743d96c0f171bca94
|
7
|
+
data.tar.gz: 75d9e22b116bbd216490b8a2eb562927240bf42c82fa25b9fd270a7a83ae79174781a0d30d7904cdcb81bf8c3e4492399071eebff116f21c1b3c98bb479de845
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: ipwebcam_sensor2020.rb
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
require 'open-uri'
|
7
|
+
|
8
|
+
|
9
|
+
class IPWebcamSensor2020
|
10
|
+
|
11
|
+
def initialize(url, interval: 4, quiet: 150, sound_threshold: 30,
|
12
|
+
debug: false)
|
13
|
+
|
14
|
+
@url, @interval, @debug = url, interval, debug
|
15
|
+
@quiet, @sound_threshold = quiet, sound_threshold
|
16
|
+
@exe_motion, @exe_sound, @exe_motionsound = [], [], []
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def onmotion_enter(&blk)
|
21
|
+
@exe_motion[0] = blk if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def onmotion_leave(&blk)
|
25
|
+
@exe_motion[1] = blk if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
def onmotionsound_start(&blk)
|
29
|
+
@exe_motionsound[0] = blk if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
def onmotionsound_end(&blk)
|
33
|
+
@exe_motionsound[1] = blk if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
def onsound_start(&blk)
|
37
|
+
@exe_sound[0] = blk if block_given?
|
38
|
+
end
|
39
|
+
|
40
|
+
def onsound_end(&blk)
|
41
|
+
@exe_sound[1] = blk if block_given?
|
42
|
+
end
|
43
|
+
|
44
|
+
def start()
|
45
|
+
|
46
|
+
@prev_motion, @prev_loud, @prev_motionsound = false, false, false
|
47
|
+
@old_sound = []
|
48
|
+
|
49
|
+
loop do
|
50
|
+
|
51
|
+
h = JSON.parse(open(@url).read, symbolize_names: true )
|
52
|
+
|
53
|
+
motion = motion_active(h[:motion_active][:data])
|
54
|
+
sound = sound_event(h[:sound][:data])
|
55
|
+
|
56
|
+
if @exe_motionsound[0] and motion and sound and not @prev_motionsound then
|
57
|
+
@exe_motionsound[0].call
|
58
|
+
@prev_motionsound = true
|
59
|
+
elsif @exe_motionsound[1] and @prev_motionsound and not motion
|
60
|
+
@exe_motionsound[1].call
|
61
|
+
@prev_motionsound = false
|
62
|
+
end
|
63
|
+
|
64
|
+
puts h.inspect if @debug
|
65
|
+
|
66
|
+
sleep @interval
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# Handles 1 or more motion_active results of value 1.0 or 0.0
|
73
|
+
# require url to contain *sense* param with value *motion_active*
|
74
|
+
#
|
75
|
+
def motion_active(a)
|
76
|
+
|
77
|
+
rawtime, raw_motion = a.last
|
78
|
+
time = Time.at(rawtime.to_s[0..-4].to_i)
|
79
|
+
motion = raw_motion.first.to_i == 1
|
80
|
+
|
81
|
+
if @exe_motion[0] and motion and not @prev_motion then
|
82
|
+
|
83
|
+
@exe_motion[0].call()
|
84
|
+
|
85
|
+
|
86
|
+
elsif @exe_motion[1] and not motion and @prev_motion then
|
87
|
+
|
88
|
+
@exe_motion[1].call()
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
@prev_motion = motion
|
93
|
+
|
94
|
+
puts [time, motion] if @debug
|
95
|
+
|
96
|
+
return motion == true
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def sound_event(a)
|
101
|
+
|
102
|
+
soundlevels = if @old_sound.any? then
|
103
|
+
|
104
|
+
all_sound = (@old_sound + a).uniq
|
105
|
+
timestamp = @old_sound.last[0]
|
106
|
+
all_sound.reverse.take_while {|x,y| x != timestamp}.reverse
|
107
|
+
else
|
108
|
+
a
|
109
|
+
end
|
110
|
+
|
111
|
+
levels = soundlevels.map do |rawtime, raw_vol|
|
112
|
+
time = Time.at(rawtime.to_s[0..-4].to_i)
|
113
|
+
vol = raw_vol.first
|
114
|
+
vol
|
115
|
+
end
|
116
|
+
|
117
|
+
threshold = @quiet + @sound_threshold = 30
|
118
|
+
|
119
|
+
loud = levels.max > threshold
|
120
|
+
puts loud ? 'noisy' : 'quiet' if @debug
|
121
|
+
|
122
|
+
if @exe_sound[0] and loud and not @prev_loud then
|
123
|
+
|
124
|
+
@exe_sound[0].call
|
125
|
+
|
126
|
+
elsif @exe_sound[1] and not loud and @prev_loud
|
127
|
+
|
128
|
+
@exe_sound[1].call
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
@prev_loud = loud
|
133
|
+
@old_sound = a
|
134
|
+
|
135
|
+
return loud == true
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipwebcam_sensor2020
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
b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zdGVyQGphbWVzcm9iZXJ0
|
27
|
+
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAJmmKl2H3dQFr387cIxZJ1zLryafXOIVJjU4hO+Ji
|
29
|
+
zB3CO9mcJG2SJsWLUXk8PJvhNhcrhIpLW3vBy5o6a13Xn/aDrsKFEdNlqY1Qe9fv
|
30
|
+
b7PHufwDByy76BCNulMhhjeDZxAt7wqaUb2XsudgumF9Ei5CF8FzpMjtDlwCyVbR
|
31
|
+
WREalV9qaWu406ulfhQXHTgf3km6i+wDm7uN+mG+QTxOU+TYoZ3I0vGi06IFiSoV
|
32
|
+
9bYLq54h9EKev9XtcdLh49yg6lipRcQFhQ9Ar2B+5069M/m/QAo2IQOJLz18gUL6
|
33
|
+
0K8ORJ58s7gthpXUEzRXChE2iVizJwMLBoiTU8UG7OChNiPz3G1W8L0gV5YuEsJP
|
34
|
+
y/Yl711avcguSfOookRL4xSOWV/5UsIKKeAuiocCNm+v7bBmeb8n1BncRN6KAJQU
|
35
|
+
M2BJiX0+KUmYctcvGl3NIsYXhGKUYg9xUbyjnfL9EMYTGeFfCCeNyCiR6Bjw2qDA
|
36
|
+
u8phAMmDkpvLDuKikmoD8/qv
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
39
|
+
dependencies: []
|
40
|
+
description:
|
41
|
+
email: james@jamesrobertson.eu
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- lib/ipwebcam_sensor2020.rb
|
47
|
+
homepage: https://github.com/jrobertson/ipwebcam_sensor2020
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.0.3
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: 'Fetches the motion and sound event data from the IP Webcam webserver API
|
70
|
+
#Android #JSON #ipwebcam #ipcam'
|
71
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|