Vis #1

Merged
senaduka merged 3 commits from vis into master 2015-12-30 03:54:30 +01:00
7 changed files with 18 additions and 16 deletions

View File

@@ -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")
}

View File

@@ -1,7 +1,7 @@
<template name="display">
<ul>
{{#each temperatures}}
{{> temperature}}
{{#each sensorDataCollection}}
{{> sensorData}}
{{/each}}
</ul>
</template>

View File

@@ -0,0 +1,3 @@
<template name="sensorData">
<li>{{owner}} / <strong>{{temperatureValue}}°C</strong> / <strong>{{humidityValue}}%</strong> / {{created_at_formatted}}</li>
</template>

View File

@@ -1,3 +0,0 @@
<template name="temperature">
<li>{{owner}} / <strong>{{value}}°C</strong> / {{created_at_formatted}}</li>
</template>

View File

@@ -1,2 +1,2 @@
Temperatures = new Mongo.Collection("temperatures");
SensorData = new Mongo.Collection("sensorData");

View File

@@ -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()
});

View File

@@ -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 ./controller.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)