Using MQTT5 example with HIVEHQ Broker

MichaelS
Posts: 19
Joined: Mon Jul 08, 2024 12:08 am

Using MQTT5 example with HIVEHQ Broker

Postby MichaelS » Sun Jul 21, 2024 12:13 am

I am using the IDF MQTT5 example project, and have built it unmodified and can connect to Mosquito
  1. I (47716) mqtt5_example: Other event id:7
  2. I (47726) main_task: Returned from app_main()
  3. I (49036) mqtt5_example: MQTT_EVENT_CONNECTED
I now want to change the broker to HIVEHQ but am battling to get the HIVHQ URI accepted.
I have opened an account at HIVEHQ and can connect and use it successfully with a Python Paho test app I wrote using MQTT5 and TLS so I know the broker side is good.

I started by changing the line:
  1.          .broker.address.uri = CONFIG_BROKER_URL,
to my hive URI
  1.         .broker.address.uri = "d72b0b51da08402e86d06db5db25f244.s1.eu.hivemq.cloud",
It seems the URI cannot be passed in this format and my logs show:
  1. E (27296) mqtt_client: Error parse uri = d72b0b51da08402e86d06db5db25f244.s1.eu.hivemq.cloud
or this format
  1.         .broker.address.uri = "mqtt://d72b0b51da08402e86d06db5db25f244.s1.eu.hivemq.cloud",
  2. my logs:
  3. E (39766) esp-tls: [sock=54] select() timeout
  4. E (39766) transport_base: Failed to open a new connection: 32774
  5. E (39766) mqtt_client: Error transport connect
So I tried commenting out
  1.         // .broker.address.uri = CONFIG_BROKER_URL,
and adding
  1.         .broker.address.hostname = "d72b0b51da08402e86d06db5db25f244.s1.eu.hivemq.cloud",
  2.         .broker.address.port = 8883,
  3.         .broker.address.transport = MQTT_TRANSPORT_OVER_TCP,
  4. my logs:
  5. E (21096) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read(): EOF
  6. E (21096) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read() error: errno=128
So I went back to eclipse broker and tried
  1.         .broker.address.uri = CONFIG_BROKER_URL,
  2.         .broker.address.port = 8883,
  3.         .broker.address.transport = MQTT_TRANSPORT_OVER_TCP,
  4. my logs:
  5. W (30676) mqtt_client: Transport config set, but overridden by scheme from URI: transport = 1, uri scheme = mqtt
  6. E (30686) mqtt5_client: Client was not initialized
Can someone please help and explain how the broker address struct works between uri and hostname & path and give me a working solution for my HIVHQ account

Thanks

MichaelS
Posts: 19
Joined: Mon Jul 08, 2024 12:08 am

Re: Using MQTT5 example with HIVEHQ Broker

Postby MichaelS » Sun Jul 28, 2024 12:24 am

I managed to get this going with help from the HiveMQ forum which seem more active than this one :(
For the benefit of anyone else struggling with this in future...
I went to the MQTT SSL example first and followed the instructions without any modifications but could not get it to connect to the Mosquitto broker.
It turns out the certificate in the example is the problem and I think may not be a root certificate. Anyway Mosquito didn't like it.
I replace the project default CA certificate (mqtt_eclipseprojects_io.pem) contents with the Root CA certificate I got from: https://letsencrypt.org/certs/isrgrootx1.pem 1. I left the same certificate name (mqtt_eclipseprojects_io.pem) so I didn’t have to make any changes to the code.
From this I could connect the MQTT/SSL project to the Mosquitto broker using SSL.
I then returned to my MQTT5 project and added the certificate code etc from the MQTT SSL example.
I added my login credentials ID and Password.
And then everything worked.
I admit I don't understand certificates and SSL but I think some better instructions in the project readme file regarding the certificate, and changing the sample certificate file would be very helpful.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 138 guests