@@ -1,15 +1,15 @@
|
|||||||
if (Meteor.isClient) {
|
if (Meteor.isClient) {
|
||||||
|
|
||||||
Template.display.helpers({
|
Template.display.helpers({
|
||||||
temperatures: function () {
|
sensorDataCollection: function () {
|
||||||
return Temperatures.find({}, {sort: {created_at: -1}})
|
return SensorData.find({}, {sort: {created_at: -1}})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.display.events({
|
Template.display.events({
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.temperature.helpers({
|
Template.sensorData.helpers({
|
||||||
created_at_formatted: function() {
|
created_at_formatted: function() {
|
||||||
return moment(this.created_at).format("DD.MM.YYYY, hh:mm")
|
return moment(this.created_at).format("DD.MM.YYYY, hh:mm")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template name="display">
|
<template name="display">
|
||||||
<ul>
|
<ul>
|
||||||
{{#each temperatures}}
|
{{#each sensorDataCollection}}
|
||||||
{{> temperature}}
|
{{> sensorData}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
3
app/client/sensorData.html
Normal file
3
app/client/sensorData.html
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<template name="sensorData">
|
||||||
|
<li>{{owner}} / <strong>{{temperatureValue}}°C</strong> / <strong>{{humidityValue}}%</strong> / {{created_at_formatted}}</li>
|
||||||
|
</template>
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<template name="temperature">
|
|
||||||
<li>{{owner}} / <strong>{{value}}°C</strong> / {{created_at_formatted}}</li>
|
|
||||||
</template>
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
|
|
||||||
Temperatures = new Mongo.Collection("temperatures");
|
SensorData = new Mongo.Collection("sensorData");
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ if (Meteor.isServer) {
|
|||||||
prettyJson: true
|
prettyJson: true
|
||||||
});
|
});
|
||||||
|
|
||||||
Api.addRoute('temperatures', {
|
Api.addRoute('sensorData', {
|
||||||
authRequired: false
|
authRequired: false
|
||||||
}, {
|
}, {
|
||||||
post: function() {
|
post: function() {
|
||||||
Temperatures.insert({
|
SensorData.insert({
|
||||||
value: parseFloat(this.bodyParams.value),
|
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
||||||
|
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||||
owner: this.bodyParams.owner,
|
owner: this.bodyParams.owner,
|
||||||
created_at: new Date()
|
created_at: new Date()
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import Adafruit_DHT
|
|||||||
|
|
||||||
|
|
||||||
GPIO_PIN = 4
|
GPIO_PIN = 4
|
||||||
TEMPERATURE_URL = 'http://tfm.meteor.com/api/temperatures'
|
SENSORDATA_URL = 'http://tfm.meteor.com/api/sensorData'
|
||||||
SENSOR_TYPE = Adafruit_DHT.DHT11
|
SENSOR_TYPE = Adafruit_DHT.DHT11
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
owner = sys.argv[1]
|
owner = sys.argv[1]
|
||||||
else:
|
else:
|
||||||
print 'usage: sudo ./conntroler.py [OWNER]#'
|
print 'usage: sudo ./controller.py [OWNER]#'
|
||||||
print 'example: sudo ./controller.py Senad - Send temperature as Senad'
|
print 'example: sudo ./controller.py Senad - Send temperature as Senad'
|
||||||
sys.exit(1)
|
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
|
# the results will be null (because Linux can't
|
||||||
# guarantee the timing of calls to read the sensor).
|
# guarantee the timing of calls to read the sensor).
|
||||||
# If this happens try again!
|
# If this happens try again!
|
||||||
if temperature is not None:
|
if temperature is not None and humidity is not None:
|
||||||
response = requests.post(TEMPERATURE_URL, json={"owner": owner, "value": temperature})
|
response = requests.post(SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity})
|
||||||
print 'Temp={0:0.1f}*C'.format(temperature)
|
print 'Temp={0:0.1f}*C'.format(temperature)
|
||||||
|
print 'Humidity={0:0.1f}%'.format(humidity)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print 'Failed to send temperature!'
|
print 'Failed to send temperature!'
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user