HarringayMakerSpace / awsiot

ESP8266 / ESP32 examples with Amazon AWS IoT
53 stars 38 forks source link

Cannot connect #5

Closed beatle99 closed 2 years ago

beatle99 commented 2 years ago

Hi! I used your ESP8266 example code but unable to connect. I never get past the "PubSubClient connecting to a1dxdgsyyuvt28-ats.iot.us-east-1.amazonaws.com...." No errors. It just keeps printing the dots but never connects. Arduino 1.8.9, ESP8266 board 3.0.2, PubSubClient (Nick O'Leary's) version 2.6.0.

Any suggestions on how to go about debugging this? When I diff my code with yours, the only difference is the ssid, password and the certificates.

torntrousers commented 2 years ago

I've not used ESP8266s much recently, but I dug one out and gave this a try and it still works fine for me.

I used v3.0.2 of the ESP8266/Arduino core and IDE v1.8.19 and v2.8 of PubSubClient.

Check you're using a valid certificate and key from AWS, that the certifcate is active and that there is an applicable policy attached to the certificate?

A do anything AWS policy to test with is:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:*",
      "Resource": "*"
    }
  ]
}
beatle99 commented 2 years ago

I synch'd my Arduino core, IDE, and PubSubClient to match what you used. Also changed the policy to match yours. Double checked the certificate and key. But no joy.

At this point, I think it is something related to my setup, perhaps on the AWS side. I will continue digging. I appreciate you taking the time to confirm that the code still works on your ESP8266.

sborsay commented 2 years ago

If you aren't receiving your device's payload under your subscription topic in AWS IoT Core in the "MQTT test client " tab, then go to the "Monitor" tab and see if your device is even connecting. Often a device is connecting, but the payload isn't being received, the reason for this is usually a problem with your device certificates.

1 Make sure you are on a 2.4GHz network not 5GHz, the ESP device only communicates at 2.4GHz

  1. Make sure your device AWS endpoint region matches the current AWS region in your console on the browser
  1. Make sure port 8883 isn't being blocked by your network admin, this is the port that MQTT(s) traditionally communicates,

    AWS IoT Core requires you send MQTT data over secure port 8883 or 443

  2. Make sure your onboard device certificates match your AWS IoT Core region, the x509 should be fungible between regions

  3. Make sure you attach an AWS IoT Policy to your security certificates. If you have not you will see the connection on the

    monitor tab but no data will appear on the MQTT test console.

  4. Don't exceed the 128 char max payload size defined by the pub sub library unless you adjust the MAX_Packet_Size library constant

    1. Does your serial monitor look like: *M???

                                   ????????%^&???*^$#$^

    Make sure your serial monitor 'Buad" rate matches your sketch (probably 115200)

    1. For the ESP8266 only: Make sure you are using the right version of the sketch for your Arduino Board Manager. If you are not receiving

      input on AWS IoT Core because you could be using the wrong ESP8266 sketch for your current Arduino Board Manager package.

On Tue, Jul 12, 2022 at 12:23 PM beatle99 @.***> wrote:

I synch'd my Arduino core, IDE, and PubSubClient to match what you used. Also changed the policy to match yours. Double checked the certificate and key. But no joy.

At this point, I think it is something related to my setup, perhaps on the AWS side. I will continue digging. I appreciate you taking the time to confirm that the code still works on your ESP8266.

— Reply to this email directly, view it on GitHub https://github.com/HarringayMakerSpace/awsiot/issues/5#issuecomment-1182340924, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4KXRGHPYEYCPSA4OEBW53VTXA2TANCNFSM53DPDQXA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

torntrousers commented 2 years ago

Also, if you email me I'll send you the source I'm using including the key/certificate/endpoint for my test AWS account and you could try running that and if it works you know its your AWS account otherwise if it doesn;t is some problem with your build environment. - torntrousers@gmail.com

beatle99 commented 2 years ago

Deleted and recreated the device and the certificates, and it works now! Not sure about the root cause of the issue, but recreating the device got rid of the gremlins.

Many thanks to @torntrousers for going above and beyond to assist. Thanks also to @sborsay for the many helpful suggestions and things to look out for.