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

Support to MQTT, websockets, TSL #28

Open
JorgeTorres01 opened this issue Oct 3, 2021 · 1 comment
Open

Support to MQTT, websockets, TSL #28

JorgeTorres01 opened this issue Oct 3, 2021 · 1 comment

Comments

@JorgeTorres01
Copy link

JorgeTorres01 commented Oct 3, 2021

Hi,

I test the code "MQTTOverWebsocketClient" and this works fine on ports 8080 and 8090 of "test.mosquitto.org" (without encryption)

But I need to use MQTT over Websockets with TLS and authentication.
I'm using the broker "test.mosquitto.org", port 8091, to test this. But I'm not succeeding.

How can I adapt the code to implement TLS?

I try add (the same of example "MQTTSecureClient") :

String fingerprint = "7E 36 22 01 F9 7E 99 2F C5 DB 3D BE AC 48 67 5B 5D 47 94 D2";

and add :

  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  mqtt.onSecure([](WiFiClientSecure *client, String host) {
        Serial.printf("Verify: %s\r\n", host.c_str());
        return client->verify(fingerprint.c_str(), host.c_str());
    });

but the connection is not established.

can someone help me find a solution to implement MQTT over WebSockets with TLS?

Thank you.
Jorge

@JorgeTorres01
Copy link
Author

I share the code:

[ESP8266]

#include "ESP8266MQTTClient.h"
#include <ESP8266WiFi.h>

MQTTClient mqtt;

String fingerprint = "7E 36 22 01 F9 7E 99 2F C5 DB 3D BE AC 48 67 5B 5D 47 94 D2";

void setup() {
  Serial.begin(115200);  
  WiFi.begin("Redmi", "d8295353cd94");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  mqtt.onSecure([](WiFiClientSecure *client, String host) {
        Serial.printf("Verify: %s\r\n", host.c_str());
        return client->verify(fingerprint.c_str(), host.c_str());
    });

  //topic, data, data is continuing
  mqtt.onData([](String topic, String data, bool cont) {
    Serial.printf("Data received, topic: %s, data: %s\r\n", topic.c_str(), data.c_str());
    mqtt.unSubscribe("/qos0");
  });

  mqtt.onConnect([]() {
    Serial.printf("MQTT: Connected\r\n");
    mqtt.subscribe("Jorge_tests", 1);
  });

  //mqtt.begin("ws://rw:[email protected]:8080/mqtt#ClientIDxyz");
  //mqtt.begin("ws://rw:[email protected]:8090/mqtt#ClientIDxyz");
  mqtt.begin("ws://rw:[email protected]:8091/mqtt#ClientIDxyz");
  
  mqtt.readConfigs();
}

void loop() {
  mqtt.handle();
}

On ESP8266MQTTClient.cpp, funtion handle() I need comment the line with
_disconnected_cb();
to avoid crash of CPU

How can I adapt the code to implement TLS?

Thank you.
Jorge

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

1 participant