Sending files via MQTT

I want to send three files with different names and extensions via MQTT topic.
All three files are formatted text.

If possible, as a JSON string, for example {“dev”: {“file1”: “CONTENT”, “file2”: “CONTENT”, “file3”: “CONTENT”}}

I am a beginner and do not know how it should look and if it is possible at all.

Any advice would be helpful.

MQTT is definitely not meant for file transfer, generally.
Specifically, HA doesn’t have a way to read a file content that I know of.

Bottom-line: Think of another way to send your files (FTP? Samba? …)

Another alternative to investigate is Node-Red, a bit of learning up front, but very worthwhile IMHO. The file-in node can import text from a file, as a string, or msg per line, and it can be used in HA by an HA entity node, or sent via MQTT out node. The multiple files you refer to can be combined and manipulated in other nodes. For example I import text from a file on my RPi’s and display the contents as a sensor in HA. The size/contents of the files may be a limiting factor.

1 Like

@francisp, @koying
A receiver is an IoT device without file system capabilities. :frowning_face:

Any tutorial for this?

Each file contains about 1250 characters.

3 files of 1k to IoT is not exactly file transfer as I call it.
What are those files? binary / text / json/…? How often would they be transferred?

@koying,

They are text.

How often would they be transferred?

On demand. Not very often.

You could start here: https://github.com/hassio-addons/addon-node-red
and here: https://nodered.org/docs/getting-started , and maybe here https://christian-schou.dk/how-to-get-started-with-node-red-and-home-assistant/
There is lots available on the internet, just be sure its very current. The file-in and mqtt nodes will be available when you are up and running. I believe on Linux you would be able to pull in 64K of text, so your small file size should be fine.