Skip to content

Instantly share code, notes, and snippets.

@yaruno

yaruno/README.md Secret

Created February 19, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaruno/b67885ec48a9a5ae213519c9a6c825c9 to your computer and use it in GitHub Desktop.
Save yaruno/b67885ec48a9a5ae213519c9a6c825c9 to your computer and use it in GitHub Desktop.
Streamr node-red example flow with Helsinki Tram data stream

An example flow on how to read data from Helsinki Tram Stream with streamr node and display trams on map in realtime.

This flow utilizes following nodes:

  • node-red-contrib-web-worldmap
  • node-red-contrib-streamr

To use this flow you'll need a Streamr account and Streamr accounts API keys and you should acquire the free Helsinki Tram stream from Streamr marketplace. You'll also need to install streamr node red node and world map node.

Import the flow from flow.json to your node-red and adjust your Streamr account API keys to Tram demo feed to be able to listen to it. Deploy the flow and navigate to your instance of node-red with worldmap e.g. http://127.0.0.1:1880/worldmap/. Locate Finland and Helsinki from map and note the movements of trams.

[{"id":"e521cc7d.08b6d","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b56bf3bd.b31d2","type":"worldmap","z":"e521cc7d.08b6d","name":"","lat":"","lon":"","zoom":"","layer":"","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","path":"/worldmap","x":1040,"y":620,"wires":[]},{"id":"7636790.efa8588","type":"function","z":"e521cc7d.08b6d","name":"Pass filter","func":"var vehicleIds = flow.get(\"vehicleIds\") || {};\nvar delay = 15000; //ms\n\n\nif (msg.payload.veh in vehicleIds){\n if(vehicleIds[msg.payload.veh] < new Date().getTime()){\n\n vehicleIds[msg.payload.veh] = new Date().getTime()+delay;\n flow.set(\"vehicleIds\",vehicleIds);\n return msg;\n }\n \n} else {\n //console.log(vehicleIds)\n vehicleIds[msg.payload.veh] = new Date().getTime()+delay;\n flow.set(\"vehicleIds\",vehicleIds);\n}\n\n","outputs":1,"noerr":0,"x":500,"y":500,"wires":[["5207d140.86461"]]},{"id":"5207d140.86461","type":"function","z":"e521cc7d.08b6d","name":"name / lon ","func":"msg.payload.name = msg.payload.veh;\nmsg.payload.lon = msg.payload.long;\nmsg.payload.bearing = msg.payload.hdg;\nmsg.payload.speed = msg.payload.spd;\n\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":540,"wires":[["b56bf3bd.b31d2"]]},{"id":"aa4e44d6.dd6ff8","type":"debug","z":"e521cc7d.08b6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":510,"y":300,"wires":[]},{"id":"f15909ce.701e98","type":"streamr-sub","z":"e521cc7d.08b6d","name":"Tram demo feed","stream":"be18315a.88704","x":230,"y":400,"wires":[["aa4e44d6.dd6ff8","7636790.efa8588"]]},{"id":"be18315a.88704","type":"streamr-config","z":"","apiKey":"","streamId":"7wa7APtlTq6EC5iTCBy6dw"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment