Save MQTT message to file

I’m trying to write a workflow that saves an MQTT message to a file but I’m a bit lost with regard to the data types involved.

If I use the MQTT trigger without the “Only Message” option, I get this:

But the file is broken.

A lot of the bytes that should be 0 have been replaced with spaces. I’m assuming n8n tries to convert the binary MQTT message into text and removes everything that is not valid UTF-8?

So I enabled the “Only message” options of the MQTT trigger and now I’m getting this:

This seems much more promising because it looks like a byte array.

Now the question is, how can I store this thing as a file?

Hi @AndreKR - welcome to the community :tada:

I’m not too familiar (at all) with MQTT - but could you provide the JSON data from the MQTT trigger? To make sure you’re copying the actual data structure from n8n’s JSON view, you can do so by selecting the first line, then clicking the Copy button and selecting “Copy Selection”. That looks like this:

Knowing what we’re working with data structure-wise might help :slight_smile:

1 Like

Thanks for your answer and also sorry I took so long to get back to it.

I created a better test setup. Here’s the original file I’m publishing (with mosquitto_pub -t test -f beep_hi.wav): beep_hi.wav

This is the JSON data from the trigger event: trigger.json

This is the workflow (one of my attempts): Store_Rhasspy_audio.json

And here is what gets stored: example.wav

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.