garden_messenger 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7b25c790bf561282f4fb0e150d2a6d5e75cbae1f7e2a7176af43a25caef39d9
4
- data.tar.gz: 9e7109e232c79bea95bba4a1a7b885809bcddbd909af94f9ed5bb7ba26f72700
3
+ metadata.gz: 9c62f2e95f39628a4b0b1d82302e02cdd2ee8fa8c6e1d526499ac57ded6b078d
4
+ data.tar.gz: 3ceb8b89feafa04ffb436d0431b1b945b39861e719c2c05351875b91010e3f50
5
5
  SHA512:
6
- metadata.gz: 2d90a0176635a0c122c70f169c9233bcfe7cad1851b8abf2ba3f855ea8e5f27093a10ea1a28614b00608cc7a8b3832f725a1e5740b41fac4ab671f9de293122c
7
- data.tar.gz: 99a55d17590b04f90e76a2c4ec6680f46e7c40179629681bac3b7c5da15a1fdbd2b3e0b66ad771982479bda83f81db9fb728b7bcf9389b0c6b847d97d2a85754
6
+ metadata.gz: d2cdf5b607b90830c0d273792a2c44fd5b93bf3bdfe8ac18a3c7f677e374eedaac10b980f315d2a1881e451eeb43de8d7fa46f1ea734da7b9f1a224547b01c61
7
+ data.tar.gz: e0ce5bb9f48bf987897c26e2915ca833187f47ccfb94ae304e87be58a61771c4edb3864bfabd2e67b810c19a0d6543c6ffffd1bb1c4e25fe3ed916b1d66d6b29
data/.rubocop.yml CHANGED
@@ -1,2 +1,4 @@
1
+ Style/WordArray:
2
+ Enabled: false
1
3
  inherit_from:
2
4
  - https://raw.githubusercontent.com/siegy22/dotfiles/c4b42f0bba4e4eb0a573d538ecc99266be90a8f8/rubocop.yml
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- garden_messenger (0.2.0)
4
+ garden_messenger (0.3.0)
5
5
  action_cable_client (~> 3.0)
6
6
  http (~> 4.1)
7
7
  thor (~> 0.20)
data/README.md CHANGED
@@ -6,6 +6,7 @@ Collects data of [AtlasScientific](https://www.atlas-scientific.com/) and [myStr
6
6
 
7
7
  Currently supported:
8
8
 
9
+ - [x] [DHT22 temperature and humidity sensor](https://www.adafruit.com/product/385)
9
10
  - [x] [pH Kit](https://www.atlas-scientific.com/product_pages/kits/ph-kit.html)
10
11
  - [x] [Conductivity Kit](https://www.atlas-scientific.com/product_pages/kits/ec_k1_0_kit.html)
11
12
  - [x] [Temperature Kit](https://www.atlas-scientific.com/product_pages/kits/temp_kit.html)
@@ -2,6 +2,13 @@ require 'thor'
2
2
 
3
3
  module GardenMessenger
4
4
  class CLI < Thor
5
+ map %w[--version -v] => :__print_version
6
+
7
+ desc '--version, -v', 'print the version'
8
+ def __print_version
9
+ puts GardenMessenger::VERSION
10
+ end
11
+
5
12
  desc 'report MONITOR_URL TOKEN [options]', 'Report to a monitor which is located on MONITOR_URL'
6
13
  option 'wattage-switch-host'
7
14
  option 'update-rate'
@@ -19,15 +26,26 @@ module GardenMessenger
19
26
  ec = GardenMessenger::AtlasScientific::EC.new
20
27
  wattage = GardenMessenger::Wattage.new(options['wattage-switch-host'])
21
28
 
29
+ begin
30
+ require 'dht-sensor-ffi'
31
+ rescue LoadError
32
+ warn 'Failed to load dht-sensor-ffi, air temperature and humidity are disabled. ' \
33
+ 'To enable it, install dht-sensor-ffi: https://github.com/chetan/dht-sensor-ffi'
34
+ end
35
+
22
36
  reporter.report! do
23
- data = { air_temp: 0.0, humidity: 0.0 }
37
+ data = {}
24
38
 
25
- data[:wattage] = wattage.get if options.key?('wattage-switch-host')
26
39
  data[:water_temp] = water_temperature.take_reading
40
+ wattage_thread = Thread.new { wattage.get }
27
41
  ph_thread = Thread.new { ph.take_reading_with_temperature_compensation(data[:water_temp]) }
28
42
  ec_thread = Thread.new { ec.take_reading_with_temperature_compensation(data[:water_temp]) }
43
+ dht_thread = Thread.new { DhtSensor.read(4, 22) } if defined?(DhtSensor)
44
+ data[:wattage] = wattage_thread.value
29
45
  data[:ph] = ph_thread.value
30
46
  data[:ec] = ec_thread.value
47
+ data[:air_temp] = dht_thread.value.temperature if defined?(DhtSensor)
48
+ data[:humidity] = dht_thread.value.humidity if defined?(DhtSensor)
31
49
 
32
50
  data
33
51
  end
@@ -35,7 +35,7 @@ module GardenMessenger
35
35
  puts 'Connection established with monitor ' \
36
36
  "on #{@monitor_url}"
37
37
  end
38
- Thread.new do
38
+ thread = Thread.new do
39
39
  loop do
40
40
  data = yield
41
41
  puts "Sending data: #{data.to_json}" if @verbose
@@ -44,6 +44,7 @@ module GardenMessenger
44
44
  sleep @update_rate
45
45
  end
46
46
  end
47
+ thread.abort_on_exception = true
47
48
  end
48
49
 
49
50
  client.disconnected do
@@ -1,3 +1,3 @@
1
1
  module GardenMessenger
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garden_messenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Siegrist
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-05 00:00:00.000000000 Z
11
+ date: 2019-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: action_cable_client