Commit 05de8798 authored by Miguel Tavares's avatar Miguel Tavares
Browse files

added listener and samples route

parent 5a1b9ef2
......@@ -18,18 +18,21 @@ const communications = new Messaging(broker, username, password, routingKeys, vh
communications.registerPublicationReceiver(function(message) {
console.log("> messageHandler: msg.content = \"" + message.content.toString() + "\"");
const data = JSON.parse(JSON.stringify(message.content.toString()));
const data = JSON.parse(JSON.parse(JSON.stringify(message.content.toString())));
if(pointer >= 30) pointer = 0;
circularBuffer[pointer++] = data;
});
/**
* get the messages that came via pubsub
*/
router.route('/temperatures').get((req, res, next) => {
const data = JSON.parse(JSON.stringify(circularBuffer));
res.json({ data });
router.route('/samples').get((req, res, next) => {
const responseData = { "list_of_rows": [
{ "name": "x", series: circularBuffer.map(item => ({ "value": item["x"], "name": item.date }))},
{ "name": "y", series: circularBuffer.map(item => ({ "value": item["y"], "name": item.date }))},
{ "name": "z", series: circularBuffer.map(item => ({ "value": item["z"], "name": item.date }))}
] }
res.json(responseData);
})
module.exports = (app) => router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment