mywx_pusher 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9ec0d7c9204f5beaa5097924fc9aba09bf2b55f4b40d69cfd7f66828c1a79ab
4
+ data.tar.gz: 5362f43110723562fbaeabe0a5991e086f83a692bbb1e3ac19156ffedd809b07
5
+ SHA512:
6
+ metadata.gz: 06be247c4db31474969c10dd5b7a576a8e488726d35a818f320e8ffb32ca92dfb76c20b4889c4b55c78028dfbc13964334ba3b51604f7c5207c7d7c8b93534b9
7
+ data.tar.gz: 0a04a1e7c903ed4ffcef33799e143aaa51fa9ec55d06f9fa61b1face84e2631a91f61beb476f97858255ded81314421af6b167cdc6c40726363f384cbb2f3351
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ *.gem
11
+
12
+ .byebug_history
13
+ .idea
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,27 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+ Layout/LineLength:
5
+ Max: 120
6
+ Style/TrailingCommaInArrayLiteral:
7
+ EnforcedStyleForMultiline: consistent_comma
8
+ Style/TrailingCommaInHashLiteral:
9
+ EnforcedStyleForMultiline: consistent_comma
10
+ Style/FormatString:
11
+ Enabled: false
12
+ Style/FormatStringToken:
13
+ Enabled: false
14
+ Style/Documentation:
15
+ Enabled: false
16
+ Metrics/ClassLength:
17
+ Enabled: false
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+ Metrics/AbcSize:
21
+ Enabled: false
22
+ Metrics/CyclomaticComplexity:
23
+ Enabled: false
24
+ Metrics/PerceivedComplexity:
25
+ Enabled: false
26
+ Style/SymbolArray:
27
+ MinSize: 1
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in mywx_pusher.gemspec
6
+ gemspec
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mywx_pusher (0.1.0)
5
+ weatherlink (~> 0.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.1)
11
+ diff-lcs (1.4.4)
12
+ parallel (1.20.1)
13
+ parser (3.0.0.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (12.3.3)
17
+ regexp_parser (2.0.2)
18
+ rexml (3.2.4)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.0)
32
+ rubocop (1.7.0)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.1.5)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.8, < 3.0)
37
+ rexml
38
+ rubocop-ast (>= 1.2.0, < 2.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 2.0)
41
+ rubocop-ast (1.3.0)
42
+ parser (>= 2.7.1.5)
43
+ ruby-progressbar (1.10.1)
44
+ ruby-units (2.3.1)
45
+ unicode-display_width (1.7.0)
46
+ weatherlink (0.1.0)
47
+ ruby-units (~> 2.3)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ mywx_pusher!
54
+ rake (~> 12.0)
55
+ rspec (~> 3.0)
56
+ rubocop (~> 1.7)
57
+
58
+ BUNDLED WITH
59
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jeremy Cole
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # MyWX Pusher
2
+
3
+ MyWX Pusher allows you to send the data directly from a Davis Instruments weather station using a [WeatherLink Live](https://www.davisinstruments.com/weatherlink/) or [AirLink](https://www.davisinstruments.com/airlink/) to [MyWX](https://www.mywx.live/) for real time display on your weather panel.
4
+
5
+ ## Installation
6
+
7
+ Or install it yourself as:
8
+
9
+ ```
10
+ $ gem install mywx_pusher
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Create your station on [MyWX](https://www.mywx.live/) and get the station slug and secret key, and run `mywx_pusher` as follows:
16
+
17
+ ```
18
+ mywx_pusher -w <local ip address> -s <station slug> -k <secret key>
19
+ ```
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at [jeremycole/mywx_pusher](https://github.com/jeremycole/mywx_pusher).
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'mywx_pusher'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'logger'
5
+ require 'optparse'
6
+ require 'ostruct'
7
+ require 'mywx_pusher'
8
+
9
+ class MywxPusherCommand
10
+ attr_reader :options
11
+
12
+ class BadOptionError < StandardError; end
13
+ class CollectError < StandardError; end
14
+ class PushError < StandardError; end
15
+
16
+ def initialize
17
+ initialize_options
18
+ end
19
+
20
+ def initialize_options
21
+ @options = OpenStruct.new(
22
+ mywx_base_uri: 'https://www.mywx.live/',
23
+ mywx_station_slug: nil,
24
+ mywx_secret_key: nil,
25
+ interval: 10
26
+ )
27
+ end
28
+
29
+ def logger
30
+ @logger ||= Logger.new($stderr, level: :info)
31
+ end
32
+
33
+ def option_parser
34
+ @option_parser ||= OptionParser.new do |opts|
35
+ opts.on('-h', '--help', 'Show this help.') do
36
+ puts opts
37
+ exit 0
38
+ end
39
+
40
+ opts.on('-d', '--debug', 'Enable debug mode') { logger.level = Logger::DEBUG }
41
+
42
+ opts.on('-w', '--weatherlink-host=HOST', '') { |o| options.weatherlink_host = o }
43
+
44
+ opts.on('-b', '--mywx-base-uri=URI', '') { |o| options.mywx_base_uri = o }
45
+ opts.on('-s', '--mywx-station-slug=SLUG', '') { |o| options.mywx_station_slug = o }
46
+ opts.on('-k', '--mywx-secret-key=KEY', '') { |o| options.mywx_secret_key = o }
47
+
48
+ opts.on('-i', '--interval=SECONDS', '') { |o| options.interval = o.to_i }
49
+ end
50
+ end
51
+
52
+ def parse_options(args)
53
+ option_parser.parse!(args)
54
+ validate_options
55
+
56
+ self
57
+ end
58
+
59
+ def validate_options
60
+ raise BadOptionError, 'Missing required --mywx-station-slug/-s option' unless options.mywx_station_slug
61
+ raise BadOptionError, 'Missing required --mywx-secret-key/-k option' unless options.mywx_secret_key
62
+ raise BadOptionError, 'Missing required --weatherlink-host/-w option' unless options.weatherlink_host
63
+
64
+ true
65
+ end
66
+
67
+ def mywx_push_data_uri
68
+ @mywx_push_data_uri ||= URI.join(options.mywx_base_uri, "/stations/#{options.mywx_station_slug}/push_data")
69
+ end
70
+
71
+ def collect_data
72
+ logger.debug("Collecting data from #{options.weatherlink_host}...")
73
+
74
+ ts = Time.now.to_i
75
+
76
+ begin
77
+ current_conditions = client.current_conditions
78
+ rescue StandardError => e
79
+ raise CollectError, e
80
+ end
81
+
82
+ iss_record = current_conditions.find { |sd| sd.record_type.id == 1 }
83
+ lss_pressure_record = current_conditions.find { |sd| sd.record_type.id == 3 }
84
+
85
+ data = {
86
+ ts: ts,
87
+ temperature: iss_record.temp.scalar.to_f.round(2),
88
+ dew_point: iss_record.dew_point.scalar.to_f.round(2),
89
+ humidity: iss_record.hum.scalar.to_f.round(2),
90
+ pressure: lss_pressure_record.bar_sea_level.scalar.to_f.round(2),
91
+ wind_speed: iss_record.wind_speed_avg_last_1_min.scalar.to_f.round(2),
92
+ wind_direction: iss_record.wind_dir_scalar_avg_last_1_min.scalar.to_i,
93
+ rain_rate: iss_record.rain_rate_last.scalar.to_f.round(2),
94
+ solar_radiation: iss_record.solar_rad.scalar.to_f.round(2),
95
+ }
96
+
97
+ logger.debug("Collected data (#{data.size} variables): #{data}")
98
+
99
+ data
100
+ end
101
+
102
+ def post_data(data)
103
+ logger.debug("Sending data (#{data.size} variables)...")
104
+ response = Net::HTTP.post_form(mywx_push_data_uri, { secret_key: options.mywx_secret_key, data: data.to_json })
105
+
106
+ unless response.code == '200'
107
+ raise PushError, "Response from MyWX API: #{response.code} #{response.message}: #{response.body}"
108
+ end
109
+
110
+ logger.debug("Response from MyWX API: #{response.code} #{response.message}")
111
+ true
112
+ end
113
+
114
+ def client
115
+ @client ||= WeatherLink::LocalClient.new(
116
+ host: options.weatherlink_host,
117
+ desired_units: WeatherLink::METRIC_WEATHER_UNITS
118
+ )
119
+ end
120
+
121
+ def run
122
+ logger.info(
123
+ format(
124
+ 'Collecting from %s, pushing to %s every %i seconds...',
125
+ options.weatherlink_host,
126
+ mywx_push_data_uri,
127
+ options.interval
128
+ )
129
+ )
130
+
131
+ loop do
132
+ begin
133
+ data = collect_data
134
+ post_data(data)
135
+ logger.info("Collected and pushed #{data.size} variables.")
136
+ rescue StandardError => e
137
+ logger.warn("Failed to collect or send data: #{e.class.name}: #{e}")
138
+ end
139
+ sleep options.interval # TODO: should try to align
140
+ end
141
+ end
142
+ end
143
+
144
+ MywxPusherCommand.new.parse_options(ARGV).run
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mywx_pusher/version'
4
+ require 'weatherlink'
5
+
6
+ module MywxPusher
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MywxPusher
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/mywx_pusher/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mywx_pusher'
7
+ spec.version = MywxPusher::VERSION
8
+ spec.authors = ['Jeremy Cole']
9
+ spec.email = ['jeremy@jcole.us']
10
+
11
+ spec.summary = 'Weather data pusher for MyWX'
12
+ spec.description = 'Push weather data from a Davis Instruments weather station to MyWX in real time'
13
+ spec.homepage = 'https://github.com/jeremycole/mywx_pusher'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency('rake', '~> 12.0')
30
+ spec.add_development_dependency('rspec', '~> 3.0')
31
+ spec.add_development_dependency('rubocop', '~> 1.7')
32
+
33
+ spec.add_dependency('weatherlink', '~> 0.1')
34
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mywx_pusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Cole
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: weatherlink
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ description: Push weather data from a Davis Instruments weather station to MyWX in
70
+ real time
71
+ email:
72
+ - jeremy@jcole.us
73
+ executables:
74
+ - mywx_pusher
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - exe/mywx_pusher
90
+ - lib/mywx_pusher.rb
91
+ - lib/mywx_pusher/version.rb
92
+ - mywx_pusher.gemspec
93
+ homepage: https://github.com/jeremycole/mywx_pusher
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ homepage_uri: https://github.com/jeremycole/mywx_pusher
98
+ source_code_uri: https://github.com/jeremycole/mywx_pusher
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.6.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Weather data pusher for MyWX
118
+ test_files: []