Hi
With that little code, it's hard to tell... ;D
You could also take a look here (https://github.com/bkeevil/mqtt) to see if there should be a solution to your conundrum...
Regards Benny
https://github.com/cutec-chris/TMQTTClientNope, tested against mosquitto and my own new synapse-mqtt-broker (finished last night), IT DOES NOT WORK!
This works but writes an error.
I use mqtt for controlling a cluster of rpi's ( 16 x Raspberry Zero 2 W for 64 cores in total , super computing for less than 250 euro)