Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting MQTT connection...failed, rc=-2 try again in 5 seconds #14

Open
gunnicus opened this issue Dec 21, 2018 · 12 comments
Open

Attempting MQTT connection...failed, rc=-2 try again in 5 seconds #14

gunnicus opened this issue Dec 21, 2018 · 12 comments

Comments

@gunnicus
Copy link

Hi, I'm using NodeMCU (ESP-12E Module). ESP8266 2.5.0-Beta1, Certificates are copied correctly.

This is the error I'm getting : Attempting MQTT connection...failed, rc=-2 try again in 5 seconds

Here is the output:

SDK:3.0.0-dev(c0f7b44)/Core:2.5.0-beta1=20499901/lwIP:STABLE-2_1_2_RELEASE/glue:1.0-4-gc434c6f/BearSSL:2398cc6
sta config unchangedscandone
wifi evt: 2
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt

connected with OPTUSV943A48, channel 6
dhcp client start...
wifi evt: 0
......ip:192.168.0.12,mask:255.255.255.0,gw:192.168.0.1
wifi evt: 3
.Attempting MQTT connection...[hostByName] request IP for: a234567hlux1-ats.iot.us-east-1.amazonaws.com
[hostByName] Host: a234567hlux1-ats.iot.us-east-1.amazonaws.com IP: 34.206.182.75
:ref 1
BSSL: Connection will fail, no authentication method is setup:wr 250 0
:wrc 250 250 0
:ack 250
:rn 536
:rd 5, 536, 0
:rdi 536, 5
:rd 531, 536, 5
:rdi 531, 531
:c0 531, 536
:rn 1072
:rd 1072, 1072, 0
:rdi 536, 536
:c 536, 536, 1072
:rdi 536, 536
:c0 536, 536
:rn 536
:rd 536, 536, 0
:rdi 536, 536
:c0 536, 536
:rn 1072
:rd 1072, 1072, 0
:rdi 536, 536
:c 536, 536, 1072
:rdi 536, 536
:c0 536, 536
:rn 1072
:rd 1072, 1072, 0
:rdi 536, 536
:c 536, 536, 1072
:rdi 536, 536
:c0 536, 536
:rn 536
:rd 536, 536, 0
:rdi 536, 536
:c0 536, 536
:rn 525
:rd 525, 525, 0
:rdi 525, 525
:c0 525, 525
failed, rc=-2 try again in 5 seconds

@reidkersey
Copy link

I ran into this problem myself.

Follow the guide here: http://www.fhilitski.com/2016/09/connecting-mqtt-fx-to-aws-iot/ and make sure that you can connect to your IoT cloud using MQTT.fx . (Make sure to set permissions on the certificate properly, and also be sure to activate the certificate)

Use the AWS CA1: https://www.amazontrust.com/repository/AmazonRootCA1.pem

Then uncomment the line espClient.setCACert(certificates_esp8266_bin_CA, certificates_esp8266_bin_CA_len);

Change the AmazonRootCA1.pem to a DER, then hex. Add it into your code, and you should be good to go.

@sw-tt-chandershekharsuthar

hey @reidkersey
I'm trying to connect with broker with this( by CA certificate ) way but getting the same " Attempting MQTT connection...failed, rc=-2 try again in 5 seconds "
I'm using CA, RSA, Key all file which you ask in .der
I tried with hex code way too but the connection is still open.

@reidkersey
Copy link

Double check that you are using CA1. Post your code as well.

@sw-tt-chandershekharsuthar
Copy link

hey @reidkersey
I'm using this code to connect Azure IOT Hub, I just want your confirmation that Can i connect ? or this code is only for AWS IOT!

I have generated .der file from .pem file and check this code(MQTT_x509_DER), also
I have generated .der file from .pem file and .hex code from .der file and check code(MQTT_x509_bin). but found same error.
" Attempting MQTT connection...failed, rc=-2 try again in 5 seconds "

I will share my code soon. Let me verify it once again. I feel that my privatekey.pem is not perfectly converted in key.der so can you help me on that point too
Meanwhile, please review my above sentences.

@reidkersey
Copy link

reidkersey commented Feb 8, 2019 via email

@sw-tt-chandershekharsuthar

hello @reidkersey @gunnicus @copercini
I'm testing your MQTT_x509_bin example too with HEX code of CA certificate and CRT and KEY too but getting the same error " Attempting MQTT connection...failed, rc=3 try again in 5 seconds "
can you give me same advise to connect that connection
And please try with Azure cloud (IoT HUB)

@reidkersey
Copy link

Set the certs like this:
espClient.setCertificate(certificates_esp8266_bin_crt, certificates_esp8266_bin_crt_len); espClient.setPrivateKey(certificates_esp8266_bin_key, certificates_esp8266_bin_key_len); espClient.setCACert(certificates_esp8266_bin_CA, certificates_esp8266_bin_CA_len);

The certs should be an array that looks like this: unsigned char certificates_esp8266_bin_key[] = { 0x30, 0x82, 0x04, 0xa5, 0x02, 0x01, 0x00, 0x02, 0x82, ....};

@sw-tt-chandershekharsuthar

Set the certs like this:
espClient.setCertificate(certificates_esp8266_bin_crt, certificates_esp8266_bin_crt_len); espClient.setPrivateKey(certificates_esp8266_bin_key, certificates_esp8266_bin_key_len); espClient.setCACert(certificates_esp8266_bin_CA, certificates_esp8266_bin_CA_len);

The certs should be an array that looks like this: unsigned char certificates_esp8266_bin_key[] = { 0x30, 0x82, 0x04, 0xa5, 0x02, 0x01, 0x00, 0x02, 0x82, ....};

Hey @reidkersey
I already used that way too and I mention that in my previous message that:
"""
Serial.println( espClient.setCACert(certificates_esp8266_bin_CA, certificates_esp8266_bin_CA_len));
Serial.println( espClient.setCertificate(certificates_esp8266_bin_crt, certificates_esp8266_bin_crt_len));
Serial.println( espClient.setPrivateKey(certificates_esp8266_bin_key, certificates_esp8266_bin_key_len));
"""
I get all three respond "True" from espClient.setCACert(), espClient.setCertificate(), espClient.setPrivateKey()

but next I get that error " Attempting MQTT connection... ESPnodemcu failed, rc=3 try again in 5 seconds.

@DiogoVigo
Copy link

Hey, I'm having the same issues when trying to connect to AWS.

Can you share your ESP8266 Configuration? (Upload speed, etc.) I don't see any other problem, I've been trying to do this for quite a while.

Thank you

@sw-tt-chandershekharsuthar

Hey, I'm having the same issues when trying to connect to AWS.
Can you share your ESP8266 Configuration? (Upload speed, etc.) I don't see any other problem, I've been trying to do this for quite a while.

Thank you

@DiogoVigo

Board : -> NODEMCU 1.0 (ESP - 12E Module)
Flash Size: -> 4M (1M SPIFFS)
CPU Frequency: -> 80/ 160 MHz ( use both )
Debug Port: -> Disabled
Debug Level: -> SSL/ TLS_MEM/ SSL+TLS_MEM (use all three)
lwP Variant: -> v2 Lower Memory
VTables: -> Flash
Upload Speed: -> 115200
Erase Flash: -> Only Sketch
Port: -> /dev/ttyU...

update back here if you got any path or solution to publish the data

@Aqsa44
Copy link

Aqsa44 commented Mar 5, 2019

I have faced the above issue but after using the help from this tutorial finally I am able to sort out all the issues
https://raphberube.com/blog/2019/02/18/Making-the-ESP8266-work-with-AWS-IoT.html ..

@noahcoad
Copy link

Help plz. I'm getting this same "rc=-2" error. I'm using the most recent example, and a set of certs converted to DEM that I've tested, it's connecting to wifi and loading the private key and certs fine, but then showing this error.

Here is my code: mqtt_x509_DER.ino.txt

And the console log output: log.txt

I'm able to test my certs and connection by manually publishing a message on a topic with the same certs using:
mosquitto_pub --cert 75cb57542f-certificate.pem.crt --key 75cb57542f-private.pem.key --cafile AmazonRootCA1.pem -h a1ybm1dzxx22hk-ats.iot.us-west-2.amazonaws.com -p 8883 -t 'testing' -q 1 -m '{"message": "Hello World"}'

And I converted the crypto files with:
openssl rsa -inform PEM -outform DER -text -in 75cb57542f-private.pem.key -out private.der
openssl x509 -outform der -in 75cb57542f-certificate.pem.crt -out cert.der
openssl x509 -outform der -in AmazonRootCA1.pem -out ca.der

Board = Generic ESP8266 Module
Flash Frequency = 80 MHz
Upload Speed = 115200
Flash Size = 1MB (128KB SPIFFS)

Using an ESP-01 with 1MB FLASH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants