Thing.mqtt.connect() is generating exception - IOError at line 393 of mqtt.mqtt.connect



I’m trying to run ‘Controlled_publish-period’ example program on ESP32 board using Zerynth Studio r2.1.2-base version(Windows 10 OS). I have created a thing/certificate/policies in AWS IoT and connected the thing-certificate-policies. Same information has been entered in thing.conf.json file in the project.

When I uplink the program I get an exception at thing.mqtt.connect().
IOError at line 393 of mqtt.mqtt.connect
raised at line 503 of mqtt.mqtt._connect
raised at line 760 of mqtt.mqtt._handle_connack
raised at line 165 of socket.recv

What could be the reason for this?

Thank you


Hi @Adu,

it seems the connection has been refused: it may be due to a wrong policy for example.
Have you tried to follow our video tutorial?



Thank you for your reply!

I think I figured out the cause. I was not creating AWS ‘thing’ using Zerynth tool-chain commands in command prompt, in other words I was not creating ‘thing’ using “ztc aws add-things” command. Instead I was trying to use existing ‘thing’ by providing ‘thing’ details in thing.conf.json file.

I got following questions;

  1. Why do we need to bind AWS IoT things to Zerynth project using a ‘ztc aws add-things’ command? Can’t we manually provide the thing information in ‘thing.config.json’ file?
  2. How to bind already existing thing to the project?

Thank you



Can anyone respond to my questions posted in the previous post. Still looking for the answer.

Thank you


Hi @Adu,

the ztc aws group of commands allows to easily create multiple things for multiple devices to be programmed with the same firmware, moreover it simplifies the process of creating things and certificates, but it is not mandatory at all.

Of course you can manually edit the thing.conf.json file but be careful in placing the right key and certificate inside the project (renamed to private.pem.key and certificate.pem.crt) with the certificate having a valid policy attached to it.

You can find more info here:


I ran into almost the same issue you have/had.

My situation: Controlled publish period

As you can see, I don’t get errors, but the device simply hangs on: “connecting to mqtt broker…”. I can’t figure out what would be wrong…

I created the thing with certificates, renamed them, created policy and linked it all together. Can you point me in the right direction? Or do you know a way to debug this in more detail?