From dc93c4e8a9512533197b58e73f1f1d274908b5cd Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Tue, 19 Feb 2019 23:52:50 +0000
Subject: Fix kitchen
---
scarecrow.rb | 42 ++++++++++++++++++++++++++++++++++++++++--
views/index.erb | 3 ++-
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/scarecrow.rb b/scarecrow.rb
index 2fbc2ab..fff656d 100644
--- a/scarecrow.rb
+++ b/scarecrow.rb
@@ -30,13 +30,21 @@ class Humidity
property :value, Float
end
+class Moisture
+ include DataMapper::Resource
+ property :id, Serial
+ property :device, String
+ property :timestamp, DateTime
+ property :value, Float
+end
+
def init
DataMapper.auto_migrate!
DataMapper.auto_upgrade!
# sleep 10
Thread.new do
MQTT::Client.connect('192.168.0.59') do |c|
- c.subscribe('+/temperature', '+/humidity')
+ c.subscribe('+/temperature', '+/humidity', '+/moisture')
loop do
while !c.queue_empty? do
topic, message = c.get
@@ -57,6 +65,8 @@ def handle_msg(topic, msg)
handle_humidity_msg(device_id, msg)
elsif type == "temperature"
handle_temp_message(device_id, msg)
+ elsif type == "moisture"
+ handle_moisture_message(device_id, msg)
end
end
@@ -74,16 +84,28 @@ def handle_temp_message(device_id, msg)
end
end
+def handle_moisture_message(device_id, msg)
+ moisture = Moisture.create(timestamp: DateTime.now, device: device_id, value: msg)
+ moisture.errors.each do |error|
+ puts error
+ end
+end
+
get '/' do
# send_file File.join(settings.public_folder, 'index.html')
@temp_prop = Temperature.last(device: "cricket0")[:value]
@humidity_prop = Humidity.last(device: "cricket0")[:value]
@temp_air = Temperature.last(device: "mercury")[:value]
@humidity_air = Humidity.last(device: "mercury")[:value]
+ @temp_kitchen = Temperature.last(device: "mercury")[:value]
+ @humidity_kitchen = Humidity.last(device: "cricket1")[:value]
+ @moisture_kitchen = Moisture.last(device: "cricket1")[:value]
time_prop = Temperature.last(device: "mercury")[:timestamp]
time_air = Temperature.last(device: "cricket0")[:timestamp]
+ time_kitchen = Temperature.last(device: "cricket1")[:timestamp]
@time_formatted_prop = time_prop.strftime("%A, %d %b %Y %l:%M %p")
@time_formatted_air = time_air.strftime("%A, %d %b %Y %l:%M %p")
+ @time_formatted_kitchen = time_kitchen.strftime("%A, %d %b %Y %l:%M %p")
erb :index
# return "#{temp_val}°C and #{humidity_val}% humidity at #{time_formatted}"
end
@@ -91,6 +113,7 @@ end
get '/temperature/:device_id' do
device_id = "mercury" if (params[:device_id] == "air" || params[:device_id] == "kitchen")
device_id = "cricket0" if (params[:device_id] == "propagator")
+ device_id = "cricket1" if (params[:device_id] == "kitchen")
device_id ||= params[:device_id]
temp = Temperature.last(device: device_id)[:value]
return "#{temp}"
@@ -99,20 +122,35 @@ end
get '/humidity/:device_id' do
device_id = "mercury" if (device_id == "air" || device_id == "basement")
device_id = "cricket0" if (device_id == "propagator")
+ device_id = "cricket1" if (device_id == "kitchen")
humidity = Humidity.last(device: device_id)[:value]
"#{humidity}"
end
+get '/moisture/:device_id' do
+ device_id = "mercury" if (device_id == "air" || device_id == "basement")
+ device_id = "cricket0" if (device_id == "propagator")
+ device_id = "cricket1" if (device_id == "kitchen")
+ moisture = Moisture.last(device: device_id)[:value]
+ "#{moisture}"
+end
+
get '/metrics' do
content_type :text
temp_prop = Temperature.last(device: "cricket0")[:value]
humidity_prop = Humidity.last(device: "cricket0")[:value]
temp_air = Temperature.last(device: "mercury")[:value]
humidity_air = Humidity.last(device: "mercury")[:value]
+ temp_kitchen = Temperature.last(device: "cricket1")[:value]
+ humidity_kitchen = Humidity.last(device: "cricket1")[:value]
+ moisture_kitchen = Moisture.last(device: "cricket1")[:value]
"humidity_basement #{humidity_air}
humidity_propagator #{humidity_prop}
+humidity_kitchen#{humidity_kitchen}
temperature_basement #{temp_air}
-temperature_propagator #{temp_prop}"
+temperature_propagator #{temp_prop}
+temperature_kitchen #{temp_kitchen}
+moisture_kitchen #{moisture_kitchen}"
end
init
diff --git a/views/index.erb b/views/index.erb
index f22328b..d9de593 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -8,7 +8,8 @@
thebluegarden
Basement: <%= @temp_air %>°C and <%= @humidity_air %>% humidity at <%= @time_formatted_air %>
- Propagator: <%= @temp_prop %>°C and <%= @humidity_prop %>% humidity at <%= @time_formatted_prop %>
+ Propagator (Chillis): <%= @temp_prop %>°C and <%= @humidity_prop %>% humidity at <%= @time_formatted_prop %>
+ Kitchen (Peas & Spinach): <%= @temp_kitchen %>°C, <%= @humidity_kitchen %>% humidity and <%= @moisture_kitchen %> anti-moistures at <%= @time_formatted_prop %>
--
cgit v1.2.3
From a8ffed6ff775154aeeed91aa0c87bbc9e42a9d3b Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Wed, 20 Feb 2019 00:09:20 +0000
Subject: SPAAAAAACE
---
scarecrow.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scarecrow.rb b/scarecrow.rb
index fff656d..e6cb303 100644
--- a/scarecrow.rb
+++ b/scarecrow.rb
@@ -97,7 +97,7 @@ get '/' do
@humidity_prop = Humidity.last(device: "cricket0")[:value]
@temp_air = Temperature.last(device: "mercury")[:value]
@humidity_air = Humidity.last(device: "mercury")[:value]
- @temp_kitchen = Temperature.last(device: "mercury")[:value]
+ @temp_kitchen = Temperature.last(device: "cricket1")[:value]
@humidity_kitchen = Humidity.last(device: "cricket1")[:value]
@moisture_kitchen = Moisture.last(device: "cricket1")[:value]
time_prop = Temperature.last(device: "mercury")[:timestamp]
@@ -146,7 +146,7 @@ get '/metrics' do
moisture_kitchen = Moisture.last(device: "cricket1")[:value]
"humidity_basement #{humidity_air}
humidity_propagator #{humidity_prop}
-humidity_kitchen#{humidity_kitchen}
+humidity_kitchen #{humidity_kitchen}
temperature_basement #{temp_air}
temperature_propagator #{temp_prop}
temperature_kitchen #{temp_kitchen}
--
cgit v1.2.3
From c4777ea1fe0daeef5ba7d8480bbd5a264ed6660d Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Thu, 21 Feb 2019 12:50:09 +0000
Subject: Add timelapse video to page
---
views/index.erb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/views/index.erb b/views/index.erb
index d9de593..b2ddf1f 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -14,7 +14,9 @@
-
+