However, my Arduino fails to connect to the MQTT broker. I've double checked everything i've done. Could there be any steps I am missing or something I am doing wrong? (Using Windows instead of Macbook from arduino's tutorial).
I checked that my certificate is active on aws, I can't find anywhere to activate my "thing" though, if possible.
REFUSED is when there is something wrong with the TLS connection, which includes the server-side Amazon Root Certificate, which I see no mention of in the tutorial; or your client certificate and private key. If everything is good on the TLS side, that means AWS can ID the Thing by its certificate.
The connection timeout defaults to 30 seconds. If you get TIMEOUT immediately, that is likely a policy violation. The tutorial creates "a very open policy for testing", which is an understatement: it is maximally open. That may help to get a working demo, but doesn't help if you're trying to debug an issue later.
Your certificate has one or more policies attached. In a real policy, you will have one or more Statements for the iot:ConnectAction, with a corresponding Resource that (starts with arn:aws:iot:<region>:<account>: and) ends like for example
client/ThatName -- exactly that name
client/ThatName-* -- that name (and a hyphen) as a prefix
client/${iot:Connection.Thing.ThingName} -- the exact name of the Thing
The name must be set via mqttClient.setId. The tutorial does not set it, and the client falls back to the random-ish default name as described in the code comment. It's supposed to work with the "anything goes" policy (but I've never tried it).
Okay, thank you very much for the input! I am getting a refused connection, and I do believe it has something to do with the authentication not working.
I put the request into the code and not the actual certificate that came from AWS. I had to open the .pem file in notepad that I downloaded from AWS and copy paste the certificate into the code then it worked.
Alright so to clarify here, he downloaded the certificate file from AWS and then he copied the contents into const char SECRET_CERTIFICATE[] = R"( -----BEGIN CERTIFICATE----- M.....== -----END CERTIFICATE----- )"; And the contents of that file are longer than the one that your board generates so please COPY FROM THE FILE AND NOT THE BOARD OUTPUT.