Capture payload

How could I capture payloads from a device and save payload as json string to a file?

as additional info for the reason of this, is to grab the textual content to use in a data model explaining data flow from some devices.

Hi @Lars_Andersson,

Just a couple questions to help me understand your use case. Are the device payloads currently being sent to Losant, and if so, how? Additionally, would the file be saved to Losant Files or elsewhere?

Thanks!
Julia

yes they are being sent to Losant via MQTT.
Yes, just need to save to a Losant file for a test.

If you want to store just the latest payload to a file, you can do that by using the Device: State trigger with a File: Create node. The payload will need be Json encoded, so you will need a Json: Encode node in between.

I could not find a way to append data to a file. File: Create node only allows to overwrite its contents. So, if you want to add payloads one by one, you will need to use workflow storage to store the current list as an array, add the new payload to the array, and then overwrite the file with the new list and update the workflow storage.

I did try to read the current list from the file itself using the Http Node, but I kept getting stale values probably due to http caching.

I wonder what is the size limit for a single item in Workflow storage?

1 Like