Recently I just contributed to an open source project. The link for the project is as following:
This is a python library that I use to record messages that are published by MQTT. The reason why I want to record the messages is because I want to play it back another time, so I don’t have to, let say, make the sensors/hardware push the data again.
This library is already working great but I see the opportunity for me to contribute to an open source project, by adding a few new features to this library.
What it is
MQTT Recorder - That’s the name of this library. It is a simple command line tool for recording and replaying MQTT messages.
Record
To record MQTT messages, you can simply run as following:
mqtt-recorder --host localhost --mode record --file recording.csv
What it does is it will connect to the MQTT broker that is hosted in localhost, record the MQTT messages, and store it into recording.csv.
Once you finish recording the messages, you can stop it from recording by CTRL+C.
Replay
To replay the recording, simply run as following:
mqtt-recorder --host localhost --mode replay --file recording.csv
Contribution
Previously, I only showed the basic use of recording and replaying the messages. But when using it, I need to add my own configuration, such as using username and password for authentication, defining client_id for identity, and using SSL for secure data transmission. However, in version 1.2.0, it does not support client_id and to use insecure TLS certs.
Hence, I added two new features which are, passing a value to parameter client_id and enable insecure TLS.
First, I modified the __main__.py file in mqtt_recorder. I added 2 arguments, where to define --client_id and --tls_insecure.
So --client_id will receive the input as a string, while --tls_insecure will receive the input as a boolean.
Then go to the main() function, to pass the arguments in the function.
I defined the argument client_id inside the MqttRecorder class. The code is:
args.client_id
At the same time, I defined the argument for --tls_insecure, which is located in the SslContext class. The code is:
args.tls_insecure
Now, I have added the code for defining parameters at __main__.py.
Proceed on, the file that is needed to modify is recorder.py, located at mqtt_recorder.
Go to SslContext class, to add the argument tls_insecure, and define the variable. An additional line of code to receive the value based on the parameters was added.
Next, go to MqttRecorder class. In __init__ function, to define parameter client_id with a string type.
client_id: str
After the parameter is defined, it can now be used in the MQTT library. The client_id can now be passed to the MQTT Client class.
self.__client = mqtt.Client(client_id=client_id)
Lastly, an if statement for tls_insecure was added. This is only needed if the --enable_ssl parameter is True. The if statement is used only when the parameter is passed, then the tls_insecure_set function is executed.
That's how you add client_id and enable insecure TLS features. I hope this helps!
Notes:
|> 20 July 2023 - My pull request still not merge: https://github.com/rpdswtk/mqtt_recorder/pull/5, however you can use the updated version here: https://github.com/Tester2009/mqtt_recorder
|> 7 August 2023 - Finally, my pull request has been merged on 5th August, 2023.
Top comments (3)
Hey, nice idea! I'm developing a time series database for blob data that works as a ring buffer and provides an HTTP API for accessing the data over time intervals. github.com/reductstore/reductstore. It doesn't have blob size limits like other TSDBs. Would you be interested in an additional backend to store data in addition to CSV files?
Oh... I see that the project is no longer active =( That's a shame.
great thinking! this will massively impact the community. keep it up!