Setting up the python script with paho-mqtt
- Paho-mqtt is the library we used to implement mqtt messaging in python. Since blender uses the python module, installing this library had to be done a little differently to if it were VSCode. The steps were as follows;
- Locate the blender python dictionary (python.exe) this can be done in blender by running a file that has the following code;
- import sys
- print(sys.executable)
- Open command prompt and go into the python dictionary using the path and add -m ensurepip (this ensures that pip is installed)
- To install the paho-mqtt use -m pip install paho-mqtt.
- To double check it works, we tried importing it into the blender python script.
Python script for initializing and implementing MQTT
The format that MQTT follows is as such:
The comments in the above code specify what each line represents and how its set up. Throughout the section, we will highlight how this format was adjusted for our project.
Important notes
- The client_ID initialisation was done differently before so a lot of sources have the old version which will not work with python 3 so this is the new way of doing it. It was found here; https://eclipse.dev/paho/files/paho.mqtt.python/html/migrations.html
- The only things changed during adapting this standard code to our project was our on_message logic, the published string and the topics.
- For our project, the publisher was irrelevant as blender was not publishing anywhere, just recieving new updates.