iSpinal - IBM Spinal Hackathon

Overview

This is the flow used by the joint winning iSpinal team for the IBM Spinal Hackathon held at IBM Hursley on 14-15th September 2017. It takes in data from IoT enabled devices and Weather Company API; combines them into a single JSON packet, outputted through websockets for the application built with Ionic.

Team Members

Dan Cunnington - IBM UK Adam Quinton - IBM UK Richard Betteridge - NHS Graduate Scheme Tom Akins - NHS Graduate Scheme

[{"id":"deb0d57.1c46528","type":"tab","label":"IoT and Weather","disabled":false,"info":""},{"id":"2f8fcc5c.fefaac","type":"ibmiot in","z":"deb0d57.1c46528","authentication":"quickstart","apiKey":"","inputType":"evt","deviceId":"a64378e391b2","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT","service":"quickstart","allDevices":"","allApplications":"","allDeviceTypes":true,"allEvents":true,"allCommands":"","allFormats":"","qos":0,"x":130,"y":280,"wires":[["4152c049.1ef71"]]},{"id":"b2d23bcc.c02d28","type":"debug","z":"deb0d57.1c46528","name":"","active":true,"console":"false","complete":"true","x":730,"y":280,"wires":[]},{"id":"4152c049.1ef71","type":"function","z":"deb0d57.1c46528","name":"formatAndInfo","func":"var obj = {\n    \"ambTemp\"   : \"\",\n    \"bodyTemp\"  : \"\",\n    \"outSTemp\"  : \"\",\n    \"humidity\"  : \"\",\n    \"BPM\"       : \"\",\n    \"oxygenSat\" : \"\"\n} ;\n\n////////amb temp////////s\nobj.ambTemp = Math.round(msg.payload.d.temp);\n\n///////////////////body temp//////////////////\nvar bodyTemp;\nvar potmeter1 = msg.payload.d.potentiometer1;\nbodyTemp = potmeter1 * 100;\n\nobj.bodyTemp = bodyTemp.toFixed(1);\n\n//////////////////humidity/////////////////\nvar humid;\nvar potmeter2 = msg.payload.d.potentiometer2;\nhumid = potmeter2 * 100;\n\nobj.humidity = Math.round(humid);\n\n/////////////outside temp////////////\nobj.outSTemp = context.global.outside;\n\n/////////////BPM///////\nobj.BPM = context.global.bpm;\n\n////////////oxygen Sat/////////\nobj.oxygenSat = context.global.oxSat;\n\n//////////get Time Stamp///////\nvar timeStmp = Date.now();\n\n////////////Final obj/////////\nvar objList = {\"obj\" : [\n        {\"type\" : \"ambTemp\",\n        \"data\" : {\"x\" : timeStmp, \"y\" : obj.ambTemp}\n    },\n        {\"type\" : \"bodyTemp\",\n        \"data\" : {\"x\" : timeStmp, \"y\" : obj.bodyTemp}\n    },\n        {\"type\" : \"outSTemp\",\n        \"data\" : {\"x\" : timeStmp, \"y\" : obj.outSTemp}\n    },\n        {\"type\" : \"humidity\",\n        \"data\" : {\"x\" : timeStmp, \"y\" : obj.humidity}\n    },\n        {\"type\" : \"BPM\",\n        \"data\" : {\"x\" : timeStmp, \"y\" : obj.BPM}\n    },\n        {\"type\" : \"oxygenSat\",\n        \"data\" : {\"x\" : timeStmp, \"y\" : obj.oxygenSat}\n    }\n    \n    ]};\n\nmsg.payload = JSON.stringify(objList);\nreturn msg\n\n","outputs":1,"noerr":0,"x":400,"y":280,"wires":[["b2d23bcc.c02d28","ed2ec43f.b1c69","ad8513b.07bd6f"]],"inputLabels":["outTemp"]},{"id":"8dc10b82.6b6258","type":"inject","z":"deb0d57.1c46528","name":"","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":true,"x":150,"y":420,"wires":[["773b8f58.2802"]]},{"id":"773b8f58.2802","type":"weather_insights","z":"deb0d57.1c46528","name":"currentObs","host":"twcservice.mybluemix.net","service":"/observations.json","geocode":"51.0268,1.3973","units":"m","language":"","x":330,"y":420,"wires":[["17086569.72d4bb","e580ee88.4be11"]]},{"id":"17086569.72d4bb","type":"function","z":"deb0d57.1c46528","name":"getTemp","func":"context.global.outside = msg.observation.temp;","outputs":1,"noerr":0,"x":580,"y":380,"wires":[[]]},{"id":"e580ee88.4be11","type":"debug","z":"deb0d57.1c46528","name":"","active":false,"console":"false","complete":"true","x":730,"y":420,"wires":[]},{"id":"ed2ec43f.b1c69","type":"websocket out","z":"deb0d57.1c46528","name":"dataFeed","server":"5f0a744c.3f5d4c","client":"","x":740,"y":340,"wires":[]},{"id":"ad8513b.07bd6f","type":"cloudant out","z":"deb0d57.1c46528","name":"","cloudant":"","database":"ispinal","service":"spinal-hack-ispinal-cloudantNoSQLDB","payonly":false,"operation":"insert","x":730,"y":200,"wires":[]},{"id":"7e9caae0.e712f4","type":"weather_insights","z":"deb0d57.1c46528","name":"48Hours","host":"twcservice.mybluemix.net","service":"/forecast/hourly/48hour.json","geocode":"51.0268,1.3973","units":"m","language":"","x":280,"y":500,"wires":[["9e4cf7ed.fa9d18"]]},{"id":"4cb39041.40b85","type":"debug","z":"deb0d57.1c46528","name":"","active":false,"console":"false","complete":"true","x":730,"y":500,"wires":[]},{"id":"9e4cf7ed.fa9d18","type":"function","z":"deb0d57.1c46528","name":"formatForcast","func":"var wf = msg.forecasts;\n\nvar list = [];\n\n\nfor (var i = 0; i < wf.length; i++) {\n    var obj = {};\n    obj.temp = wf[i].temp;\n    obj.descrip = wf[i].phrase_22char;\n    obj.windSpeed = wf[i].wspd;\n    obj.windDir = wf[i].wdir_cardinal;\n    obj.rainProb = wf[i].pop;\n    obj.rainType = wf[i].precip_type;\n    obj.time = wf[i].fcst_valid_local;\n        \n    list.push(obj);\n}\n\n\n\n\n//msg.payload = JSON.stringify(list);\nmsg.payload = list;\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":500,"wires":[["4cb39041.40b85","7c5ad07a.5602c"]]},{"id":"27818b46.f77064","type":"http in","z":"deb0d57.1c46528","name":"weather","url":"/weather","method":"get","upload":false,"swaggerDoc":"","x":110,"y":500,"wires":[["7e9caae0.e712f4"]]},{"id":"7c5ad07a.5602c","type":"http response","z":"deb0d57.1c46528","name":"weatherResponse","statusCode":"","headers":{},"x":770,"y":540,"wires":[]},{"id":"100aba2b.08265e","type":"ibmiot in","z":"deb0d57.1c46528","authentication":"quickstart","apiKey":"","inputType":"evt","deviceId":"b827eb5387ea","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"BPM","service":"quickstart","allDevices":"","allApplications":"","allDeviceTypes":true,"allEvents":true,"allCommands":"","allFormats":"","qos":0,"x":130,"y":180,"wires":[["75f68b6e.ac8824","fc0942ed.e28208"]]},{"id":"75f68b6e.ac8824","type":"debug","z":"deb0d57.1c46528","name":"","active":false,"console":"false","complete":"true","x":290,"y":200,"wires":[]},{"id":"fc0942ed.e28208","type":"function","z":"deb0d57.1c46528","name":"BPM & OxygenSat","func":"context.global.bpm = msg.payload.BPM;\ncontext.global.oxSat = msg.payload.oxygenSaturation;","outputs":1,"noerr":0,"x":330,"y":160,"wires":[[]]},{"id":"c98ea64e.6d7df8","type":"inject","z":"deb0d57.1c46528","name":"","topic":"","payload":"cold","payloadType":"str","repeat":"","crontab":"","once":false,"x":130,"y":620,"wires":[["5b34cc8d.d83aac","6b6979dc.fe30b"]]},{"id":"5b34cc8d.d83aac","type":"websocket out","z":"deb0d57.1c46528","name":"","server":"844f9d14.a173c","client":"","x":300,"y":580,"wires":[]},{"id":"6b6979dc.fe30b","type":"debug","z":"deb0d57.1c46528","name":"","active":true,"console":"false","complete":"payload","x":290,"y":640,"wires":[]},{"id":"c293eec1.0fc588","type":"inject","z":"deb0d57.1c46528","name":"","topic":"","payload":"hot","payloadType":"str","repeat":"","crontab":"","once":false,"x":130,"y":740,"wires":[["edfd6e1d.ec7ff8","f3cc5686.86e408"]]},{"id":"f3cc5686.86e408","type":"debug","z":"deb0d57.1c46528","name":"","active":true,"console":"false","complete":"false","x":290,"y":760,"wires":[]},{"id":"edfd6e1d.ec7ff8","type":"websocket out","z":"deb0d57.1c46528","name":"","server":"844f9d14.a173c","client":"","x":300,"y":700,"wires":[]},{"id":"5f0a744c.3f5d4c","type":"websocket-listener","z":"","path":"/ws/dataFeed","wholemsg":"false"},{"id":"844f9d14.a173c","type":"websocket-listener","z":"","path":"/ws/alerts","wholemsg":"false"}]
rlionheart92

Flow Info

created 1 month, 1 week ago

Node Types

Core
  • debug (x6)
  • function (x4)
  • http in (x1)
  • http response (x1)
  • inject (x3)
  • websocket out (x3)
  • websocket-listener (x2)
Other

Tags

  • ibm
  • hackathon
  • iot
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option