Skip to content

Instantly share code, notes, and snippets.

@anabelengp
Created October 16, 2015 08:36
Show Gist options
  • Save anabelengp/823bae72b1423d0ff729 to your computer and use it in GitHub Desktop.
Save anabelengp/823bae72b1423d0ff729 to your computer and use it in GitHub Desktop.
Basic server listening to fiware orion ContextBroker suscriptions
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