Public MQTT broker (eg. flespi.io)

Hi Everyone,

So far I was able to cover my needs with ESPHome. But now I want to add a sensor outside my LAN and use a public broker (flespi.io or HiveMQ).
So I did a configuration (relevant parts only):

logger:
  level: very_verbose

mqtt:
  id: mqtt_client
  broker: mqtt.flespi.io
  port: 8883
  username: [myTokenToAccess]
  topic_prefix: Test/m5stick
  birth_message:
    topic: <device_name>/state
    payload: online
  will_message:
    topic: <device_name>/state
    payload: offline

Even with VERY_VERBOSE all I get is

INFO Successfully uploaded program.
INFO Starting log output from Test/m5stick/debug
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server

Then the log stops. With port 1883 I only get one response “MQTT Server Connected”.
The ports are open on the network, no firewall blocking; with MQTT Explorer I can connect (with the same access token), create topics, send values…

Also I tried to send a json:

  - platform: axp192
    address: 0x34
    i2c_id: bus_a
    update_interval: 30s
    battery_level:
      name: "${friendly_name} Battery Level"
      id: "m5stick_batterylevel"
      on_value:
        - mqtt.publish_json:
            topic: "m5stick_batterylevel"
            payload: |-
              root["Battery"] = id(m5stick_batterylevel).state;

So I tried to add “”, use user and password, tried HiveMQ etc… now I’m out of ideas.

Does anyone have a good idea here? I cannot imagine that I a the first one trying something like that.

Thanks a lot
Fenki

And with that port 1883 (non ssl) it works like expected?

SSL Fingerprints

On the ESP8266 you have the option to use SSL connections for MQTT. […]

TLS with esp-idf (esp32)

If used with the esp-idf framework a TLS connection to a mqtt broker can be established. The servers CA certificate is required to validate the connection. […]

from:

And just in case you have nabu casa cloud you can also just use webhooks with esphome :rocket:

No, it’s not working either. The only difference is that the log stops after the first line - it seems the ESP is hanging. With port 8883 the log gets longer but also slower.

Once back home I will try to get the SH1 fingerprint (I only have web access at the moment).
Also on an ESP32 I will try the certificate you linked.

So I am back home. I tried with a modified configuration:

esp32:
  board: m5stick-c
  framework:
    type: esp-idf

mqtt:
  id: mqtt_client
  broker: mqtt.flespi.io
  port: 8883
  username: [myTokenToAccess]
  topic_prefix: Test/m5stick
  birth_message:
    topic: <device_name>/state
    payload: online
  will_message:
    topic: <device_name>/state
    payload: offline
  skip_cert_cn_check: False
  idf_send_async: True
  certificate_authority: |
      -----BEGIN CERTIFICATE-----
      MIIGQTCCBSmgAwIBAgIMfhZZcLfhD5IOiRADMA0GCSqGSIb3DQEBCwUAMEwxCzAJ
      BgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSIwIAYDVQQDExlB
      bHBoYVNTTCBDQSAtIFNIQTI1NiAtIEc0MB4XDTIzMDEwODA4MjMxNloXDTI0MDIw
      OTA4MjMxNVowFjEUMBIGA1UEAwwLKi5mbGVzcGkuaW8wggEiMA0GCSqGSIb3DQEB
      AQUAA4IBDwAwggEKAoIBAQC2EFF1WQLEDkN4kk0xWUbD/AfO5JutZeO4VGrZ6bIs
      drFzOYyAhOi0I9MLLHqZKBK4YC+U8twW9uX9TOawm0o2WtGUkauC4MI+/ibzXYfV
      7XYc9+3GDRz7kERaMxwLDm3iYNMAaW4GRXD8Zz39MU1xOynby7U1qo0Joqg7ymSe
      1jDJ2d2D7gcrM8dXhcDyGY0mKu4OO0EiamfJ14uQWQzFCh3fbqzxRZhuHoHoQE14
      Sciy5NcB6SzipXmkf5NfmPlJjW6pz5S+yHMQv1COfvOx1bpTVqaVdKTr1ZIuxGtV
      UKhN0MbpWK7M2+mRsBfyflR1k3mb4a230hsgsuqocUsfAgMBAAGjggNXMIIDUzAO
      BgNVHQ8BAf8EBAMCBaAwgZMGCCsGAQUFBwEBBIGGMIGDMEYGCCsGAQUFBzAChjpo
      dHRwOi8vc2VjdXJlLmdsb2JhbHNpZ24uY29tL2NhY2VydC9hbHBoYXNzbGNhc2hh
      MjU2ZzQuY3J0MDkGCCsGAQUFBzABhi1odHRwOi8vb2NzcC5nbG9iYWxzaWduLmNv
      bS9hbHBoYXNzbGNhc2hhMjU2ZzQwVwYDVR0gBFAwTjAIBgZngQwBAgEwQgYKKwYB
      BAGgMgoBAzA0MDIGCCsGAQUFBwIBFiZodHRwczovL3d3dy5nbG9iYWxzaWduLmNv
      bS9yZXBvc2l0b3J5LzAJBgNVHRMEAjAAMEEGA1UdHwQ6MDgwNqA0oDKGMGh0dHA6
      Ly9jcmwuZ2xvYmFsc2lnbi5jb20vYWxwaGFzc2xjYXNoYTI1Nmc0LmNybDAhBgNV
      HREEGjAYggsqLmZsZXNwaS5pb4IJZmxlc3BpLmlvMB0GA1UdJQQWMBQGCCsGAQUF
      BwMBBggrBgEFBQcDAjAfBgNVHSMEGDAWgBRPy6yowu+r3YNva7/OmD1cWCV2FTAd
      BgNVHQ4EFgQUnLMd3+26thwj02l4N5xeQUs/fGowggGABgorBgEEAdZ5AgQCBIIB
      cASCAWwBagB3AG9Tdqwx8DEZ2JkApFEV/3cVHBHZAsEAKQaNsgiaN9kTAAABhZB6
      F8AAAAQDAEgwRgIhAOenJFl0l0kOS/j86+cRER6ZmHuMcs0ilLToROPpKNd3AiEA
      reMOeyo3hZFvTAVcnDOwrmPQ1uAmWyzzDYKorlut+VcAdgDuzdBk1dsazsVct520
      zROiModGfLzs3sNRSFlGcR+1mwAAAYWQehf2AAAEAwBHMEUCIG9xjUjImOV3OMyt
      0+PBt3n4HoCFGn6V2/vdm6oOWTf4AiEAti2vFp1psfqHyCOAL+lHr4Jt9ZGtYvn1
      VdT+Sox1uwAAdwBIsONr2qZHNA/lagL6nTDrHFIBy1bdLIHZu7+rOdiEcwAAAYWQ
      ehdAAAAEAwBIMEYCIQCfb0uulNWu4RupKbyr5vYQe4yTMBUhJfWBajLl3ITIHwIh
      AOpfWqYpVaVdrxvQk11UV+76HBginlG4FnUycv7bRp15MA0GCSqGSIb3DQEBCwUA
      A4IBAQBkcuFPR8sL6Id9SJi7DfCNGISO9gnyO/SZEG3BcpjYeP5IqhrbWon16zna
      t5usRj3K1nZEIOtQ9in85Htz5KiG/5Ymph2nqGNG46pZwT4nWYXKzn3ivwX289bI
      Dtbmx9E0mKyQ1Ns0x4wRH4zjuFFdy1xazRUCr9ZI6L2jGlO0YQrRBW+38tGDxCJj
      JeSHeWC+CC1MXvwaYYNuwxI0zjsXXKeFqVboyyaZA4RTFpcxthjkFFo2I4OR6CWQ
      BMGLHZzy58K4092b8HDnwVVc8HZhqw2n9f5PCHpaBP47/d33hEh9e/p38RwLwgeZ
      QE1jzGtBf18vnJilDnREpRcm8h7l
      -----END CERTIFICATE-----

But still I only get the following from loglevel VERY_VERBOSE

INFO Starting log output from Test/m5stick/debug
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server
INFO Successfully reconnected to the MQTT server

Flespi.io shows no connection at all.
The token is fine: MQTT Explorer can connect with the same token on port 8883.
ALso the rest of the configuration should be fine as it connects without problems to the local mosquitto if MQTT is configured for it. But the goal is that the sensor will be outside the LAN once it works…

To me it seems as ESPHome does not connect at all.