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":[]}]

Flow Info

Created 11 years, 2 months ago
Updated 10 years ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • function (x2)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • udp in (x1)
Other
  • tab (x1)

Tags

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