From f30100e795e90b19d7ff6749da6b4fd4b4c03099 Mon Sep 17 00:00:00 2001 From: visocicaguy Date: Tue, 29 Dec 2015 23:25:11 +0100 Subject: [PATCH 1/3] Added humidity sensor data handling --- app/client/app.js | 6 +++--- app/client/display.html | 4 ++-- app/client/temperature.html | 3 --- app/common/collections.js | 2 +- app/server/startup.js | 7 ++++--- controller/controller.py | 9 +++++---- 6 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 app/client/temperature.html diff --git a/app/client/app.js b/app/client/app.js index 03ea271..f1f2201 100644 --- a/app/client/app.js +++ b/app/client/app.js @@ -1,15 +1,15 @@ if (Meteor.isClient) { Template.display.helpers({ - temperatures: function () { - return Temperatures.find({}, {sort: {created_at: -1}}) + sensorDataCollection: function () { + return SensorData.find({}, {sort: {created_at: -1}}) } }); Template.display.events({ }); - Template.temperature.helpers({ + Template.sensorData.helpers({ created_at_formatted: function() { return moment(this.created_at).format("DD.MM.YYYY, hh:mm") } diff --git a/app/client/display.html b/app/client/display.html index 03cf7be..f58e5f3 100644 --- a/app/client/display.html +++ b/app/client/display.html @@ -1,7 +1,7 @@ diff --git a/app/client/temperature.html b/app/client/temperature.html deleted file mode 100644 index a99f3e2..0000000 --- a/app/client/temperature.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/app/common/collections.js b/app/common/collections.js index aaa8038..d43b7be 100644 --- a/app/common/collections.js +++ b/app/common/collections.js @@ -1,2 +1,2 @@ -Temperatures = new Mongo.Collection("temperatures"); +SensorData = new Mongo.Collection("sensorData"); diff --git a/app/server/startup.js b/app/server/startup.js index f1caf9f..2821300 100644 --- a/app/server/startup.js +++ b/app/server/startup.js @@ -9,12 +9,13 @@ if (Meteor.isServer) { prettyJson: true }); - Api.addRoute('temperatures', { + Api.addRoute('sensorData', { authRequired: false }, { post: function() { - Temperatures.insert({ - value: parseFloat(this.bodyParams.value), + SensorData.insert({ + temperatureValue: parseFloat(this.bodyParams.temperatureValue), + humidityValue: parseFloat(this.bodyParams.humidityValue), owner: this.bodyParams.owner, created_at: new Date() }); diff --git a/controller/controller.py b/controller/controller.py index ae37883..0781f73 100644 --- a/controller/controller.py +++ b/controller/controller.py @@ -5,13 +5,13 @@ import Adafruit_DHT GPIO_PIN = 4 -TEMPERATURE_URL = 'http://tfm.meteor.com/api/temperatures' +SENSORDATA_URL = 'http://tfm.meteor.com/api/sensorData' SENSOR_TYPE = Adafruit_DHT.DHT11 if len(sys.argv) == 2: owner = sys.argv[1] else: - print 'usage: sudo ./conntroler.py [OWNER]#' + print 'usage: sudo ./controler.py [OWNER]#' print 'example: sudo ./controller.py Senad - Send temperature as Senad' sys.exit(1) @@ -26,9 +26,10 @@ humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, GPIO_PIN) # the results will be null (because Linux can't # guarantee the timing of calls to read the sensor). # If this happens try again! -if temperature is not None: - response = requests.post(TEMPERATURE_URL, json={"owner": owner, "value": temperature}) +if temperature is not None and humidity is not None: + response = requests.post(SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity}) print 'Temp={0:0.1f}*C'.format(temperature) + print 'Humidity={0:0.1f}%'.format(humidity) if response.status_code != 200: print 'Failed to send temperature!' sys.exit(2) -- 2.47.3 From 147d9ed2b86d02cfded62e0d569d1ddbddf6a390 Mon Sep 17 00:00:00 2001 From: visocicaguy Date: Tue, 29 Dec 2015 23:27:09 +0100 Subject: [PATCH 2/3] Added sensorData.html to commit --- app/client/sensorData.html | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/client/sensorData.html diff --git a/app/client/sensorData.html b/app/client/sensorData.html new file mode 100644 index 0000000..d72211c --- /dev/null +++ b/app/client/sensorData.html @@ -0,0 +1,3 @@ + -- 2.47.3 From 7c863e456ccb66a9838eee2be3ba571a82a81ca0 Mon Sep 17 00:00:00 2001 From: visocicaguy Date: Tue, 29 Dec 2015 23:39:10 +0100 Subject: [PATCH 3/3] Fixed comment in file --- controller/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/controller.py b/controller/controller.py index 0781f73..ae53570 100644 --- a/controller/controller.py +++ b/controller/controller.py @@ -11,7 +11,7 @@ SENSOR_TYPE = Adafruit_DHT.DHT11 if len(sys.argv) == 2: owner = sys.argv[1] else: - print 'usage: sudo ./controler.py [OWNER]#' + print 'usage: sudo ./controller.py [OWNER]#' print 'example: sudo ./controller.py Senad - Send temperature as Senad' sys.exit(1) -- 2.47.3