ESP-TLS couldn't get hostname over bridged network (MQTT)

Gustav
Posts: 7
Joined: Tue Aug 18, 2020 7:57 am

ESP-TLS couldn't get hostname over bridged network (MQTT)

Postby Gustav » Fri Oct 22, 2021 8:28 pm

Hello everyone!

I'm using a raspberrypi as a mosquitto broker, it also runs grafana, influxdb and nodered.
Since the raspberry is in the same room as the ESP32 that sends sensors values over mqtt, and this room is too far to be reached from a wifi repeater, I'm using a powerline to bring ethernet to this room, and the raspberry is configured to bridge the ethernet connection over wifi through its integrated wifi adapter.

Everything worked fine for months, but then I moved, and had to change the internet provider and the modem/router.
Since that moment the system stopped working, I always get this errors

Code: Select all

I (386933) MQTT_SERVICE: Other event id:7
E (386973) esp-tls: couldn't get hostname for :raspberrypi:
E (386973) esp-tls: Failed to open new connection
E (386973) TRANS_SSL: Failed to open a new connection
E (386983) MQTT_CLIENT: Error transport connect
I (386983) MQTT_SERVICE: MQTT_EVENT_ERROR
I (386993) MQTT_SERVICE: MQTT_EVENT_DISCONNECTED
Mqtt is configured to use SSL, so I HAVE to use the hostname of the raspberry as .host parameter, since i generated the certificates using that hostname.

Code: Select all

const esp_mqtt_client_config_t mqtt_cfg = {
		.host = "raspberrypi",
		.port = 8883,
		.transport = MQTT_TRANSPORT_OVER_SSL,
		.event_handle = mqtt_event_handler,
		//.use_global_ca_store = true,
		.cert_pem = ca_cert,
		.client_cert_pem = esp_cert,
		.client_key_pem = esp_key,
		.username = "xxxx",
		.password = "****"
	};
What drives me crazy is that every other device I connect to the wifi generated by the raspberry can resolve correctly the hostname, I tried PCs and a smarphones and all were able to resolve "raspberrypi".
Also, everyone in the network (even outside the bridge) can resolve "espressif"

So there must be an issue with the esp32, but I can't understand where to look, even the verbose log doesn't state more than the lines I pasted above.

What am I missing? My project is quite big, and I don't know what to show you, so please tell me what infos or code you need to help me, and I'll provide them. I'm using esp idf 4.2.

Thank you in advance!

ESP_Sprite
Posts: 9723
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP-TLS couldn't get hostname over bridged network (MQTT)

Postby ESP_Sprite » Sat Oct 23, 2021 1:37 am

It's hard to say... generally, local hostnames like this are either resolved using MDNS or by a router converting names from DHCP queries into resolvable DNS names. It could be that in your case, MDNS is the thing that does this; you could try by manually querying mdns on your ESP32. If this works, you might possibly get away with resolving the IP using this, using that IP as the hostname for mqtt and setting skip_cert_common_name_check to make it not fail because of lack of hostname... but note I'm not experienced enough with the mqtt lib to say for sure this will work.

Who is online

Users browsing this forum: Bing [Bot] and 259 guests