BJOERN_ENGELS_thermostat_exercise 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.
- checksums.yaml +7 -0
- data/bin/Thermostaat +51 -0
- data/lib/BJOERN_ENGELS_thermostat_exercise.rb +5 -0
- data/lib/app.rb +54 -0
- data/lib/app_old.rb +16 -0
- data/lib/input.rb +14 -0
- data/lib/mqtt.demo.rb +13 -0
- data/lib/proces.rb +21 -0
- data/lib/thermostaat.rb +68 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '057821fc983732b4fb5e552138894cde92c22b41'
|
4
|
+
data.tar.gz: 4091fabbe324a348e77e09d3da94daa457b618ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69c3b62e14be4214747a5bce8af4287c747eb86816d913a73bf5854919d1ea0e0a400c3098c38fe18511bf504839a32a0da30ecb949767d9d95c4495a0095d02
|
7
|
+
data.tar.gz: 81cc1b09c7fd901d1d03c790f4d87edcce15ac9ed9a2437b7344d7dd15438f12153c40971b2460801fac8b747e82c9d3cf984ccf0d4e0ffac83d0c4fac08e7b9
|
data/bin/Thermostaat
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative "bin/BJOERN_ENGELS_thermostat_exercise.rb"
|
2
|
+
|
3
|
+
input = Input.new
|
4
|
+
proces = Proces.new
|
5
|
+
mqtt.demo = MQTT.DEMO.new
|
6
|
+
|
7
|
+
options = {:temperature => nil,
|
8
|
+
:range => 1, :threshold => 20, :method=> nil}
|
9
|
+
|
10
|
+
parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Thermostat application: app.rb [options]"
|
12
|
+
|
13
|
+
opts.on('-m', '--method M', String, 'Where do you get the temperature from (mqtt, url, self) ') do |method|
|
14
|
+
options[:method] = method
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-r', '--range R' , Float , 'temperature range') do |range|
|
18
|
+
options[:range] = range
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-t', '--threshold T', Float, 'Desired temperature') do |threshold|
|
22
|
+
options[:threshold] = threshold
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-h', '--help', 'Displays Help') do
|
26
|
+
puts opts
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
parser.parse!
|
32
|
+
|
33
|
+
if options[:method] =='mqtt'
|
34
|
+
mqtt.on_change do |temp|
|
35
|
+
puts temp
|
36
|
+
mqtt.send(led.get_color)
|
37
|
+
end
|
38
|
+
mqtt.get
|
39
|
+
end
|
40
|
+
if options[:method] == 'url'
|
41
|
+
update = Thread.new do
|
42
|
+
while true do
|
43
|
+
puts ""
|
44
|
+
temp = input.url
|
45
|
+
|
46
|
+
sleep (5)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
update.join
|
50
|
+
|
51
|
+
end
|
data/lib/app.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require_relative "input.rb"
|
3
|
+
require_relative "proces.rb"
|
4
|
+
require_relative "mqtt.demo.rb"
|
5
|
+
|
6
|
+
input = Input.new
|
7
|
+
proces = Proces.new
|
8
|
+
mqtt.demo = MQTT.DEMO.new
|
9
|
+
|
10
|
+
options = {:temperature => nil,
|
11
|
+
:range => 1, :threshold => 20, :method=> nil}
|
12
|
+
|
13
|
+
parser = OptionParser.new do |opts|
|
14
|
+
opts.banner = "Thermostat application: app.rb [options]"
|
15
|
+
|
16
|
+
opts.on('-m', '--method M', String, 'Where do you get the temperature from (mqtt, url, self) ') do |method|
|
17
|
+
options[:method] = method
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-r', '--range R' , Float , 'temperature range') do |range|
|
21
|
+
options[:range] = range
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-t', '--threshold T', Float, 'Desired temperature') do |threshold|
|
25
|
+
options[:threshold] = threshold
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-h', '--help', 'Displays Help') do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
parser.parse!
|
35
|
+
|
36
|
+
if options[:method] =='mqtt'
|
37
|
+
mqtt.on_change do |temp|
|
38
|
+
puts temp
|
39
|
+
mqtt.send(led.get_color)
|
40
|
+
end
|
41
|
+
mqtt.get
|
42
|
+
end
|
43
|
+
if options[:method] == 'url'
|
44
|
+
update = Thread.new do
|
45
|
+
while true do
|
46
|
+
puts ""
|
47
|
+
temp = input.url
|
48
|
+
|
49
|
+
sleep (5)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
update.join
|
53
|
+
|
54
|
+
end
|
data/lib/app_old.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "thermostaat.rb"
|
2
|
+
|
3
|
+
foo = Thermostaat.new
|
4
|
+
read = Input.new
|
5
|
+
temp=read.download
|
6
|
+
# change.compare(1,20)
|
7
|
+
p temp
|
8
|
+
|
9
|
+
|
10
|
+
# foo.ask_temperature
|
11
|
+
# foo.get_temperature
|
12
|
+
# foo.ask_max
|
13
|
+
# foo.get_max
|
14
|
+
# foo.ask_min
|
15
|
+
# foo.get_min
|
16
|
+
# foo.temperatuur
|
data/lib/input.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
3
|
+
require "open-uri"
|
4
|
+
|
5
|
+
class Input
|
6
|
+
|
7
|
+
attr_reader:temperature
|
8
|
+
|
9
|
+
def download
|
10
|
+
@downloaded_temperature = (URI.parse('https://labict.be/software-engineering/temperature/api/temperature/fake').read).to_f
|
11
|
+
return @downloaded_temperature
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/lib/mqtt.demo.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "mqtt"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
temperature_topic = 'softwareengineering/temperature/+'
|
5
|
+
# Subscribe example
|
6
|
+
MQTT::Client.connect('mqtt.labict.be') do |client|
|
7
|
+
# If you pass a block to the get method, then it will loop
|
8
|
+
while true
|
9
|
+
client.get(temperature_topic) do |topic,message|
|
10
|
+
puts "#{topic}: #{message}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/proces.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Proces
|
2
|
+
|
3
|
+
attr_reader:range
|
4
|
+
attr_reader:threshold
|
5
|
+
attr_accessor:action
|
6
|
+
|
7
|
+
def compare (range, threshold)
|
8
|
+
@threshold = threshold
|
9
|
+
if @downloaded_temperature < (threshold-range)
|
10
|
+
@action = "verwarmen"
|
11
|
+
puts "RED"
|
12
|
+
elsif @downloaded_temperature < (threshold+range)
|
13
|
+
@action = "afkoelen"
|
14
|
+
puts "BLUE"
|
15
|
+
else
|
16
|
+
@action = "niets"
|
17
|
+
puts "GREEN"
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/thermostaat.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
|
3
|
+
class Thermostaat
|
4
|
+
|
5
|
+
|
6
|
+
require_relative 'input.rb'
|
7
|
+
require_relative 'proces.rb'
|
8
|
+
|
9
|
+
require 'open-uri'
|
10
|
+
|
11
|
+
def geef_temperatuur
|
12
|
+
read = Input.new
|
13
|
+
read.download
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def range
|
18
|
+
@range = 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def threshold
|
22
|
+
@threshold = 20
|
23
|
+
end
|
24
|
+
|
25
|
+
def proces
|
26
|
+
change = Proces.new
|
27
|
+
change.compare(@range,@threshold)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
=begin
|
32
|
+
|
33
|
+
attr_accessor :range
|
34
|
+
|
35
|
+
|
36
|
+
def ask_temperature
|
37
|
+
puts "what is the temperature?"
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_temperature
|
41
|
+
@temperature = gets.to_i
|
42
|
+
|
43
|
+
def ask_max
|
44
|
+
puts "what is the maximum temperature?"
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_max
|
48
|
+
@maximum = gets.to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def ask_min
|
52
|
+
puts "what is the minimum temperature?"
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_min
|
56
|
+
@minimum =gets.to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
def temperatuur
|
60
|
+
if @maximum < @temperature
|
61
|
+
puts "Cooling"
|
62
|
+
elsif @minimum > @temperature
|
63
|
+
puts "Heating".red
|
64
|
+
else
|
65
|
+
puts "Standby"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
=end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: BJOERN_ENGELS_thermostat_exercise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Björn Engels
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: eenvoudige termostaat app
|
14
|
+
email:
|
15
|
+
executables:
|
16
|
+
- Thermostaat
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/Thermostaat
|
21
|
+
- lib/BJOERN_ENGELS_thermostat_exercise.rb
|
22
|
+
- lib/app.rb
|
23
|
+
- lib/app_old.rb
|
24
|
+
- lib/input.rb
|
25
|
+
- lib/mqtt.demo.rb
|
26
|
+
- lib/proces.rb
|
27
|
+
- lib/thermostaat.rb
|
28
|
+
homepage: http://rubygems.org/gems/BJOERN_ENGELS_thermostat_exercise.gemspec
|
29
|
+
licenses: []
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.5.2
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: termostaat app
|
51
|
+
test_files: []
|