humble_rpi-plugin-ds18b20 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14ebb97d7eebe863b705c96d5906def410eb95b3
4
+ data.tar.gz: 056e757749c1f5fdcbf772cda113678beecc6879
5
+ SHA512:
6
+ metadata.gz: c8a5cb8622e60006cb3fe601f146d6356ac300b4e9cc5b7239136b31222ca55a8037dbcb28f59f361997a39ce388d32f723abbf648ce1c8f19e091eb451fefee
7
+ data.tar.gz: 0e70911a7e3cd9f76210130c4fedfb6cd1d61ab173cf8fc931feff1523ae4d74fd16d5d74b15a3086bae45f278e1c820b621b9616217c0ac979ccdbcccfb218d
@@ -0,0 +1,3 @@
1
+ U&>���Ad׀Ί�=݀�84��}� =8�칙���j���������7E7�\B�ύ�1��Hv�>����Q��Jo�%�שּׂ
2
+ 9Ҷ3�Z?�2�wC���Ճظ�sP!�L`e�I�/��k(pb
3
+ ����)�K��1f�B��\L(Ʋ�\l<������+RYA�i��L��l���[����٨�V�V���^� ���6�3�GZ��Rի�+I�l����O|Z�u�H�KI�U����_�
Binary file
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: humble_rpi-plugin-ds18b20sensor.rb
4
+
5
+
6
+
7
+ class HumbleRPiPluginDs18b20Sensor
8
+
9
+
10
+ def initialize(settings: {}, variables: {})
11
+
12
+ @sensor_id = settings[:id]
13
+
14
+ if @sensor_id.nil? then
15
+ raise 'HumbleRPiPluginDhtSensor: settings error: please supply an ID'
16
+ end
17
+
18
+ h = {
19
+ threshold: 1,
20
+ interval: 3,
21
+ msg_format: "%s/ds18b20_sensor/%s: temperature: %s",
22
+ pushrate: 60
23
+ }.merge settings
24
+
25
+ @threshold = h[:threshold]
26
+ @interval = h[:interval]
27
+ @msg_format = h[:msg_format]
28
+ @pushrate = h[:pushrate]
29
+
30
+ @notifier = variables[:notifier]
31
+ @device_id = variables[:device_id] || 'pi'
32
+
33
+ filename = 'w1_slave'
34
+ @filepath = File.join('/sys/bus/w1/devices/', @sensor_id, filename)
35
+
36
+ unless File.exists? @filepath then
37
+ return 'HumbleRPiPluginDs18b20Sensor error: ' + \
38
+ 'file doesn\'t exist -> ' + @filepath
39
+ end
40
+
41
+ end
42
+
43
+ def start()
44
+
45
+ puts 'ready to monitor temperature'
46
+
47
+ temp = read()
48
+ push temp
49
+ last_push = Time.now
50
+
51
+ loop do
52
+
53
+ temp = read()
54
+
55
+ if last_push + @pushrate < Time.now and \
56
+ (@old_temp - temp).abs >= @threshold then
57
+ push temp
58
+ last_push = Time.now
59
+ end
60
+
61
+ sleep @interval
62
+
63
+ end
64
+
65
+ end
66
+
67
+ alias on_start start
68
+
69
+ private
70
+
71
+ def push(temp)
72
+
73
+ @notifier.notice @msg_format % [@device_id, @sensor_id, temp]
74
+ @old_temp = temp
75
+
76
+ end
77
+
78
+ def read()
79
+
80
+ begin
81
+
82
+ buffer = File.read @filepath
83
+ a = buffer.lines
84
+ crc = a.shift =~ /YES$/
85
+ crc ? (a.shift[/t=(\d+)/,1].to_f / 1000).round(3) : 99999
86
+
87
+ rescue
88
+ 99999
89
+ end
90
+
91
+ end
92
+
93
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: humble_rpi-plugin-ds18b20
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
+ 8ixkARkWAmV1MB4XDTE2MDIyMDIwMTkyNloXDTE3MDIxOTIwMTkyNlowSDESMBAG
16
+ A1UEAwwJZ2VtbW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RYA4mLqUiCV5zrAl3RLv258cf1d
32
+ CI4GaofZ3tz8qQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-02-20 00:00:00.000000000 Z
35
+ dependencies: []
36
+ description:
37
+ email: james@r0bertson.co.uk
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/humble_rpi-plugin-ds18b20.rb
43
+ homepage: https://github.com/jrobertson/humble_rpi-plugin-ds18b20
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.8
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A Humble RPi plugin to read the ambient temperature from the DS18B20 sensor.
67
+ test_files: []
Binary file