Chat freely about anything...

User avatar
By batstru
#67888 Hi all,
I'm setting up the ESP01 to connect to a MQTT broker via TLS.
With MQTTSpy no problem, with the ESP01 no ways!... with the same certs and credentials.

Do you have any suggestion? What I'm doing wrong?
How can I debug this?


I have already the clock set to 160MHz, and the watchdog disabled.

It seems the device is crashing immediately: this is the output I get from the serial monitor:
Code: Select allc_⸮⸮rS⸮fj⸮CF⸮⸮JC⸮⸮⸮⸮⸮KBB⸮⸮⸮⸮⸮BG⸮"⸮⸮BfBN⸮B⸮FB⸮⸮BO⸮⸮F⸮GBJ⸮⸮⸮G⸮⸮Gc⸮KG⸮⸮b⸮J⸮BB⸮⸮⸮GB⸮⸮cFJ⸮"⸮⸮+bFJ⸮j⸮FC⸮⸮⸮⸮⸮⸮⸮c⸮OBB⸮⸮⸮⸮⸮⸮⸮⸮⸮b⸮⸮⸮fKB⸮J⸮⸮⸮FNB⸮FB⸮⸮⸮Cb⸮B⸮⸮bJFFBNB⸮⸮F⸮⸮B⸮⸮⸮⸮J⸮BJ⸮b⸮⸮FN⸮⸮FFN⸮kJKBJ⸮JfgF⸮⸮N⸮BCFBfF⸮BB⸮⸮⸮gWJC⸮CJjbF⸮KbJ⸮⸮n⸮KK⸮
'KB⸮B⸮Bc⸮⸮FFFO⸮⸮KBf⸮C⸮⸮⸮Fg⸮VBC⸮⸮jf⸮VF⸮JFfnJVBb⸮JK⸮⸮⸮⸮B*B⸮⸮F&⸮JF⸮⸮⸮W⸮JBF⸮BFWJB⸮⸮⸮jNV⸮⸮⸮cNbbFB⸮J⸮ʒKvO⸮Bb⸮⸮KV⸮⸮⸮F⸮⸮JFj⸮⸮⸮C⸮B⸮JB⸮⸮F⸮C⸮⸮f⸮CJ⸮N⸮⸮J⸮⸮B*&⸮⸮N⸮F⸮⸮⸮KF⸮⸮b




So, this is what I have:

certificates.h

Code: Select allunsigned char certificates_sensor3_bin_crt[] = {
  0x30, 0x82, 0x03, 0x7f, 0x30, 0x82, 0x02, 0x67, 0x02, 0x09, 0x00, 0xa9,
<CUT>
  0xbd, 0xc5, 0x19, 0x14, 0x99, 0x57, 0xe0, 0x46, 0x28, 0xde, 0x32
};
unsigned int certificates_sensor3_bin_crt_len = 899;
unsigned char certificates_sensor3_bin_key[] = {
  0x30, 0x82, 0x04, 0xa5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00,
<CUT>
  0x44, 0xe9, 0xbc, 0xa0, 0x20
};
unsigned int certificates_sensor3_bin_key_len = 1193;


Arduino ide code
(the code below is shrink down to the minimum, in the real life it's a little bigger as I added code to connect to the wifi)

Code: Select all#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "certificates.h"

WiFiClientSecure espClient;
PubSubClient client(espClient);

void setup() {
    WiFi.begin("password");
    while(WiFi.status() != WL_CONNECTED)
        delay(500);
    espClient.setCertificate(certificates_sensor3_bin_crt, certificates_sensor3_bin_crt_len);
    espClient.setPrivateKey(certificates_sensor3_bin_key, certificates_sensor3_bin_key_len);
    client.setServer("192.168.0.3", 8883);
    client.setCallback(callback);
}

void reconnect() {
    while(!client.connected()) {
        if(client.connect("ESP8266Client", "user", "password")) {
         //bla
        } else {
            delay(500);
        }
    }
}

void loop() {
    if(!client.connected()) {
        reconnect();
    }
    client.loop();
    //logic
}