Skip to content

Instantly share code, notes, and snippets.

@calderonroberto calderonroberto/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
Public WoTKit-powered API

A public API endpoint using WoTKit data to compute average sensor values.

[{"id":"ebe7f3ce.14181","type":"http in","name":"","url":"/public/average","method":"get","x":107,"y":46,"z":"bb3eb439.44c148","wires":[["f216930a.0de97"]]},{"id":"f324bec8.0cdb4","type":"function","name":"Assemble Data","func":"if (msg.payload.length === 0){\n msg.payload = {\"error\":\"no data found\"};\n return msg;\n}\n\n//Get the values as an array\nvar values = []\nvar sensors = []\nmsg.payload.map(function(element){\n values.push(element.value)\n if (sensors.indexOf(element.sensor_name) == -1 && element.sensor_name !== null)\n sensors.push(element.sensor_name)\n});\n\nvar average = values.reduce(function(previous, current, index, array) {\n return previous + current;\n}) / values.length;\n\nmsg.payload = {'average_value': average, 'sensors_parsed':sensors, 'data_points' : values.length }\nreturn msg;\n","outputs":1,"valid":true,"x":346,"y":185,"z":"bb3eb439.44c148","wires":[["ab1f116c.54e0f"]]},{"id":"f216930a.0de97","type":"http request","name":"Aggregated Data Retrieval (1 hour)","method":"GET","ret":"txt","url":"http://wotkit.sensetecnic.com/api/v1/data?text={{payload.text}}&before=3600000","x":236,"y":114,"z":"bb3eb439.44c148","wires":[["6bcbabc.f943454"]]},{"id":"6bcbabc.f943454","type":"json","name":"","x":453,"y":114,"z":"bb3eb439.44c148","wires":[["f324bec8.0cdb4"]]},{"id":"ab1f116c.54e0f","type":"http response","name":"Http Response","x":529,"y":185,"z":"bb3eb439.44c148","wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.