Skip to content

Commit 24b06db

Browse files
committedFeb 11, 2016
add interval to get data from remote
1 parent 476ecf7 commit 24b06db

File tree

5 files changed

+76
-56
lines changed

5 files changed

+76
-56
lines changed
 

‎.DS_Store

6 KB
Binary file not shown.

‎sensors-client/app/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
5656
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
5757
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
58-
<script src="bower_components/angular-gage/dist/angular-gage.js"></script>
5958
<!-- endbower -->
6059
<!-- endbuild -->
6160

‎sensors-client/app/scripts/config/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
angular.module('app.config')
22
.constant('urls', {
3-
host: 'data/',
4-
getCurrentTemperatur: 'temperatur.json'
3+
host: 'http://192.168.178.30:3000/',
4+
getCurrentTemperatur: 'getCurrentTemperatur'
55
})
66

77
.constant('gaugeconfig', {

‎sensors-client/app/scripts/controllers/main.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88
* Controller of the sensorsClientApp
99
*/
1010
angular.module('sensorsClientApp')
11-
.controller('MainCtrl', function ($scope,$http,$filter, urls, gaugeconfig) {
11+
.controller('MainCtrl', function ($scope, $http, $filter, $interval, $log, urls, gaugeconfig) {
12+
getData();
13+
$interval(function () {
14+
console.log('intervall');
15+
getData();
16+
}, 10000)
1217

13-
14-
$http({
15-
method: 'GET',
16-
url: urls.host + '' + urls.getCurrentTemperatur
17-
}).then(function successCallback(response) {
18-
gaugeconfig.title = 'Temperatur Wohnzimmer';
19-
gaugeconfig.value = $filter('number')(response.data.temperatur / 1000, 1);
20-
$scope.config = gaugeconfig;
21-
}, function errorCallback(response) {
22-
23-
});
18+
function getData() {
19+
$http({
20+
method: 'GET',
21+
url: urls.host + '' + urls.getCurrentTemperatur
22+
}).then(function successCallback(response) {
23+
gaugeconfig.title = 'Temperatur Wohnzimmer';
24+
gaugeconfig.value = $filter('number')(response.data.temperatur / 1000, 1);
25+
$scope.config = gaugeconfig;
26+
}, function errorCallback(response) {
27+
$log.error('Can not get temperatur data from sensor');
28+
});
29+
}
2430

2531
});

‎sensors/app/controllers/home.js

+56-41
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ module.exports = function (app) {
1010

1111

1212
router.get('/', function (req, res, next) {
13-
// load the single view file (angular will handle the page changes on the front-end)
14-
res.sendfile('./public/index.html');
13+
// load the single view file (angular will handle the page changes on the front-end)
14+
res.sendfile('./public/index.html');
1515
});
1616

1717
router.get('/getCurrentTemperatur', function (req, res, next) {
18-
var response ={};
19-
fs.readFile(config.data.pathTow1_slave + '/' + config.device.serial + '/' + config.data.w1_slaveFilename, 'utf8', function (err,data) {
18+
var response = {};
19+
fs.readFile(config.data.pathTow1_slave + '/' + config.device.serial + '/' + config.data.w1_slaveFilename, 'utf8', function (err, data) {
2020
if (err) {
2121
return console.log(err);
2222
}
@@ -30,55 +30,70 @@ router.get('/getCurrentTemperatur', function (req, res, next) {
3030

3131
router.get('/enableLed/:gpiopin', function (req, res, next) {
3232
var gpiopin = req.params.gpiopin;
33-
gpio.open(gpiopin, "output", function(err) {
34-
if(err){
35-
console.error('ERROR: Can not open gpio pin ' + gpiopin);
36-
res.json({status: true});
37-
}
38-
else{
39-
gpio.write(gpiopin, 1, function() {
40-
console.log('LED enabled' + gpiopin);
41-
res.json({status: true});
33+
gpio.read(gpiopin, function (err, value) {
34+
if (value != 1) {
35+
gpio.open(gpiopin, "output", function (err) {
36+
if (err) {
37+
console.error('ERROR: Can not open gpio pin ' + gpiopin);
38+
res.json({status: false});
39+
}
40+
else {
41+
gpio.write(gpiopin, 1, function () {
42+
console.log('LED enabled' + gpiopin);
43+
res.json({status: true});
44+
});
45+
}
4246
});
47+
} else {
48+
res.json({status: true});
4349
}
4450
});
51+
4552
});
4653

4754
router.get('/disableLed/:gpiopin', function (req, res, next) {
4855
var gpiopin = req.params.gpiopin;
49-
gpio.open(gpiopin, "output", function(err) { // Open pin 16 for output
50-
gpio.write(gpiopin, 1, function() { // Set pin 16 high (1)
56+
gpio.read(gpiopin, function (err, value) {
57+
if (value == 1) {
5158
gpio.close(gpiopin);
52-
});
59+
}
60+
res.json({status: value});
5361
});
54-
res.json({status: false});
62+
63+
5564
});
5665

5766
router.get('/getLedStatus', function (req, res, next) {
58-
var redLedStatus = 0;
59-
gpio.read(11, function(err, value) {
60-
console.log('11 = ' + value);
61-
redLedStatus = value; // The current state of the pin
67+
var response = [{
68+
color: 'red',
69+
gpiopin: 11,
70+
status: false
71+
},
72+
{
73+
color: 'yellow',
74+
gpiopin: 13,
75+
status: false
76+
},
77+
{
78+
color: 'green',
79+
gpiopin: 15,
80+
status: false
81+
}
82+
]
83+
gpio.read(11, function (err, value) {
84+
response[0].status = (value) ? 1 : 0;
85+
gpio.read(13, function (err, value) {
86+
response[1].status = (value) ? 1 : 0;
87+
gpio.read(15, function (err, value) {
88+
response[2].status = (value) ? 1 : 0;
89+
res.json(response);
90+
});
91+
});
6292
});
6393

64-
console.log('11 = ' + redLedStatus);
65-
var response = [{
66-
color: 'red',
67-
gpiopin: 11,
68-
status: redLedStatus
69-
},
70-
{
71-
color: 'yellow',
72-
gpiopin: 13,
73-
status: false
74-
},
75-
{
76-
color: 'green',
77-
gpiopin: 15,
78-
status: false
79-
}
80-
]
81-
82-
83-
res.json(response);
94+
95+
96+
97+
98+
8499
});

0 commit comments

Comments
 (0)
Please sign in to comment.