Created
October 16, 2015 08:36
-
-
Save anabelengp/823bae72b1423d0ff729 to your computer and use it in GitHub Desktop.
Basic server listening to fiware orion ContextBroker suscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.post('/temperature', function(req, res) { | |
var value = req.body.contextResponses[0].contextElement.attributes[0].value; | |
console.log("temperature updated at " + new Date()); | |
console.log("value: " + value); | |
res.send("OK"); | |
}); | |
app.post('/humidity', function(req, res) { | |
var value = req.body.contextResponses[0].contextElement.attributes[0].value; | |
console.log("humidity updated at " + new Date()); | |
console.log("value: " + value); | |
res.send("OK"); | |
}); | |
app.post('/luminance', function(req, res) { | |
var value = req.body.contextResponses[0].contextElement.attributes[0].value; | |
console.log("luminance updated at " + new Date()); | |
console.log("value: " + value); | |
res.send("OK"); | |
}); | |
var server = app.listen(4000, function() { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('app listening at http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment