Skip to content

Instantly share code, notes, and snippets.

@badryan
Created August 19, 2014 08:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badryan/1e53304bb8cfa1ca41ef to your computer and use it in GitHub Desktop.
Save badryan/1e53304bb8cfa1ca41ef to your computer and use it in GitHub Desktop.
AirPi with Node-RED

A very simple Node-RED flow that listens to UDP and takes data from the AirPi Python scripts. Adds udp.py that pumps AirPi data to localhost:5005.

[{"type":"tab","id":"59948db3.a66b74","label":"Sheet 1"},{"id":"3d426ec2.c2bd92","type":"mqtt-broker","broker":"api.xively.com","port":"1883","clientid":""},{"id":"3d6640c7.c299c","type":"udp in","name":"recUDP","iface":"","port":"5005","datatype":"utf8","multicast":"false","group":"","x":95,"y":196,"z":"59948db3.a66b74","wires":[["9ec5b066.613a5"]]},{"id":"45c45404.ba3bac","type":"function","name":"collectMessages","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\n\ncontext.buff = context.buff || \"\";\ncontext.count = context.count || 0;\n\n if (msg.topic != \"purge\") {\n if (context.buff.length > 0) {\n context.buff = context.buff+\"\\n\"+msg.topic+\", \"+msg.payload;\n } else {\n context.buff = msg.topic+\", \"+msg.payload;\n }\n context.count += 1; \n }\n if (context.count == 8 || (msg.payload==\"purge\" && context.count >= 1)) {\n //msg.topic = \"APIKEY/v2/feeds/FEED.csv\";\n msg.topic=\"\";\n msg.payload = context.buff;\n context.buff = \"\";\n context.count = 0;\n return msg;\n }\nreturn null;","outputs":1,"x":434,"y":195,"z":"59948db3.a66b74","wires":[["99edb9cd.661248"]]},{"id":"9ec5b066.613a5","type":"function","name":"splitMessage","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\n\nvar res = msg.payload.split(\":\");\nmsg.topic = res[0];\nmsg.payload = res[1];\nreturn msg;","outputs":1,"x":256,"y":195,"z":"59948db3.a66b74","wires":[["45c45404.ba3bac"]]},{"id":"99edb9cd.661248","type":"mqtt out","name":"publishToXively","topic":"/v2/feeds/PUTYOURFEEDID.csv","broker":"3d426ec2.c2bd92","x":629,"y":195,"z":"59948db3.a66b74","wires":[]}]
@badryan
Copy link
Author

badryan commented Aug 19, 2014

Find the rest of the files here: https://github.com/badryan/AirPi-adjust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment