Skip to content

Instantly share code, notes, and snippets.

@smadds

smadds/README.md Secret

Last active January 19, 2017 00:35
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 smadds/c9b0d75427ccc96232535322c6579703 to your computer and use it in GitHub Desktop.
Save smadds/c9b0d75427ccc96232535322c6579703 to your computer and use it in GitHub Desktop.
Log MQTT to DynamoDB

Logs all or selected MQTT activity to a DynamoDB database.

By default logs everything - change the topic in the MQTT node to be more selective (e.g. "my\path\#" or "my\topic")

In AWS create a DynamoDB table with a Partition Key "timestamp" and a Sort Key "topic". Within IAM create a programmatic user and give it full access to DynamoDB service. You'll need the public & private keys to configure the node in this flow along with the name of the table you have created.

Requires node-red-contrib-aws and configuration of your MQTT server & DynamoDB table details

[{"id":"c52154f0.f78048","type":"amazon dynamodb","z":"d0c2c5a0.2bb308","aws":"","region":"","operation":"put","tablename":"","name":"Put Data","x":640,"y":1260,"wires":[[]]},{"id":"baf5518.0160cb","type":"mqtt in","z":"d0c2c5a0.2bb308","name":"","topic":"#","qos":"2","broker":"","x":150,"y":1240,"wires":[["e32f375.4a5adc8"]]},{"id":"e32f375.4a5adc8","type":"function","z":"d0c2c5a0.2bb308","name":"Add topic & timestamp to payload","func":"var out={\n timestamp: { \"S\": new Date().toISOString() },\n topic: { \"S\": msg.topic },\n data: { \"S\": msg.payload }\n} ;\n\nmsg.payload=out;\n\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":1240,"wires":[["c52154f0.f78048","935b131d.51635"]]},{"id":"935b131d.51635","type":"debug","z":"d0c2c5a0.2bb308","name":"","active":false,"console":"false","complete":"false","x":650,"y":1220,"wires":[]},{"id":"dcc200c9.3a9b5","type":"comment","z":"d0c2c5a0.2bb308","name":"Log everything","info":"","x":140,"y":1200,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment