alex-vancoillie-thermostat-exercise 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/app +19 -4
- data/lib/led.rb +4 -0
- data/lib/log.rb +1 -0
- data/lib/relais.rb +3 -0
- data/lib/temperature.rb +2 -3
- data/lib/transport.rb +2 -0
- data/lib/user_input.rb +5 -0
- data/lib/web.rb +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99a32209873e3c93cf857588d1940a1378ddc488
|
4
|
+
data.tar.gz: 5226dfee78fd0df73188ddbb53ab771ef5763c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dee68ce75dbbe4bce299376a625596ff13ab05191d9b7b9aad24de75504e800e8c41ec633b8ddf232704f3a83b3f0bb73ed517dc2cece4dc32b445e1212ba786
|
7
|
+
data.tar.gz: 5f5df345dae12b0a628663c8cb3b32720a9289ad31bcd1e4e3e8891a756389de0ede5796f9e3ae9884e67b88119f2bcbb6ced950c30eda0ce0514a218e494086
|
data/bin/app
CHANGED
@@ -21,20 +21,20 @@ optparse = OptionParser.new do |opts|
|
|
21
21
|
opts.banner = "Usage: app.rb [options]"
|
22
22
|
|
23
23
|
# define the options, and what they do
|
24
|
-
opts.on('-m', '--method M', String, 'How to get temperature [user], [url], [mqtt]') do |method|
|
24
|
+
opts.on('-m', '--method M', String, 'How to get temperature [user], [command], [url], [mqtt]') do |method|
|
25
25
|
options[:method] = method
|
26
26
|
end
|
27
27
|
|
28
28
|
opts.on('-c', '--celsius TEMP', Float, 'Enter the temperature in Celsius') do |celsius|
|
29
|
-
options[:temperature] = temp.convert('
|
29
|
+
options[:temperature] = temp.convert(celsius, 'C')
|
30
30
|
end
|
31
31
|
|
32
32
|
opts.on('-k', '--kelvin TEMP', Float, 'Enter the temperature in Kelvin') do |kelvin|
|
33
|
-
options[:temperature] = temp.convert('
|
33
|
+
options[:temperature] = temp.convert(kelvin, 'K')
|
34
34
|
end
|
35
35
|
|
36
36
|
opts.on('-f', '--fahrenheit TEMP', Float, 'Enter the temperature in Fahrenheit') do |fahrenheit|
|
37
|
-
options[:temperature] = temp.convert('
|
37
|
+
options[:temperature] = temp.convert(fahrenheit, 'F')
|
38
38
|
end
|
39
39
|
|
40
40
|
opts.on('-r', '--range R', Float, 'Enter the range') do |range|
|
@@ -69,6 +69,21 @@ if options[:method] == 'user'
|
|
69
69
|
log.addContent(led.get_fcolor)
|
70
70
|
end
|
71
71
|
|
72
|
+
if options[:method] == 'command'
|
73
|
+
conversion = temp.convert(options[:temperature], options[:unit])
|
74
|
+
puts "The converted temperature in celsius: #{conversion} "
|
75
|
+
led.check_led(conversion, options[:set], options[:range])
|
76
|
+
relais.set(conversion, options[:set], options[:range])
|
77
|
+
|
78
|
+
puts relais.get_heating
|
79
|
+
puts relais.get_cooling
|
80
|
+
puts led.get_led
|
81
|
+
|
82
|
+
log.addContent(relais.get_heating)
|
83
|
+
log.addContent(relais.get_cooling)
|
84
|
+
log.addContent(led.get_fcolor)
|
85
|
+
end
|
86
|
+
|
72
87
|
if options[:method] == 'url'
|
73
88
|
update = Thread.new do
|
74
89
|
|
data/lib/led.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'colorize'
|
2
2
|
|
3
3
|
class Led
|
4
|
+
# this method will define which color the LED should be
|
4
5
|
def check_led(temp, set, range)
|
5
6
|
if(temp < (set - range))
|
6
7
|
@color = "0000FF".colorize(:blue)
|
@@ -14,14 +15,17 @@ class Led
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
# this method is used for the output if you run the program
|
17
19
|
def get_led
|
18
20
|
"The LED is #{@color}"
|
19
21
|
end
|
20
22
|
|
23
|
+
# this method is used to publish ONLY the hexadecimal value to the RGB-LED
|
21
24
|
def get_color
|
22
25
|
return @fcolor
|
23
26
|
end
|
24
27
|
|
28
|
+
# this method is used to write the output to the log.txt file
|
25
29
|
def get_fcolor
|
26
30
|
"The LED is #{@fcolor}"
|
27
31
|
end
|
data/lib/log.rb
CHANGED
data/lib/relais.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Relais
|
2
|
+
# this method will define if the heating and/or the cooling should be enabled
|
2
3
|
def set(temp, set, range)
|
3
4
|
if temp < (set - range)
|
4
5
|
@heating = true
|
@@ -12,10 +13,12 @@ class Relais
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
# this method tells you if the heating is enabled or not
|
15
17
|
def get_heating
|
16
18
|
"The heating is #{@heating}"
|
17
19
|
end
|
18
20
|
|
21
|
+
# this method tells you if the cooling is enabled or not
|
19
22
|
def get_cooling
|
20
23
|
"The cooling is #{@cooling}"
|
21
24
|
end
|
data/lib/temperature.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
class Temperature
|
2
|
+
# this method will convert the temperature to Celsius
|
2
3
|
def convert(temp, unit)
|
3
4
|
if(unit == "C")
|
4
5
|
@temp = temp
|
5
6
|
elsif(unit == "K")
|
6
|
-
|
7
|
-
# be "green"
|
8
|
-
@temp = temp - 273
|
7
|
+
@temp = temp - 273.15
|
9
8
|
elsif(unit == "F")
|
10
9
|
@temp = ((temp - 32) * 5 / 9)
|
11
10
|
else
|
data/lib/transport.rb
CHANGED
@@ -2,6 +2,7 @@ require 'mqtt'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
class Transport
|
5
|
+
# this method will automatically subscribe through MQTT from an mbed
|
5
6
|
def get_connection
|
6
7
|
puts "MQTT:"
|
7
8
|
temperature_topic = 'softwareengineering/thermostat/cfbnik/temperature'
|
@@ -21,6 +22,7 @@ class Transport
|
|
21
22
|
@on_change_block = block
|
22
23
|
end
|
23
24
|
|
25
|
+
# this method will publish its value through MQTT to an mbed
|
24
26
|
def send_color(color)
|
25
27
|
connection = MQTT::Client.connect('mqtt.labict.be')
|
26
28
|
my_hash = {"color" => color}
|
data/lib/user_input.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class UserInput
|
2
|
+
# this method will ask the user four questions
|
2
3
|
def askData
|
3
4
|
puts "Enter the temperature:"
|
4
5
|
@temp = gets.chomp.to_f
|
@@ -13,18 +14,22 @@ class UserInput
|
|
13
14
|
@range = gets.chomp.to_f
|
14
15
|
end
|
15
16
|
|
17
|
+
# this method will give us the temperature
|
16
18
|
def get_temp
|
17
19
|
return @temp
|
18
20
|
end
|
19
21
|
|
22
|
+
# this method will give us the wanted temperature
|
20
23
|
def get_set
|
21
24
|
return @set
|
22
25
|
end
|
23
26
|
|
27
|
+
# this method will give us the unit
|
24
28
|
def get_unit
|
25
29
|
return @unit
|
26
30
|
end
|
27
31
|
|
32
|
+
# this method will give us the range
|
28
33
|
def get_range
|
29
34
|
return @range
|
30
35
|
end
|
data/lib/web.rb
CHANGED
@@ -4,6 +4,7 @@ require 'open-uri'
|
|
4
4
|
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
5
5
|
|
6
6
|
class Web
|
7
|
+
# this method will give us the current temperature through a URL
|
7
8
|
def url
|
8
9
|
@temp = (URI.parse("https://labict.be/software-engineering/temperature/api/temperature/fake").read).to_f
|
9
10
|
puts @temp
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alex-vancoillie-thermostat-exercise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Vancoillie
|
@@ -9,8 +9,22 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-05-09 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A thermostat gem (small application exercise)
|
14
28
|
email: alex.vancoillie@student.vives.be
|
15
29
|
executables:
|
16
30
|
- app
|