- allow_anonymous true
- port 1883
- listener 9001
- protocol websockets
I just wanted to get started with MQTT for some self made home automation.
Therefore I was planning on using MQTT over websockets to connect to a local mosquitto MQTT broker.
Until now I was able to connect to my broker via the MQTT TCP example. I was also able to connect to the public mosquitto MQQT test server via the websockets example.
But if I try to connect to my local hosted server I always get the error at the bottom from the ESP.
To my understanding the connection is refused by the ESP because the server sends an unsupported fixed header byte.
But I don't know why and how to fix that.
My System: Windows 10 Ultimate 64 bit (Added incoming and outgoing firewall rule on port 9001)
ESP IDF: 4.2
Controller: ESP 32
Mosquitto broker: 2.0.5
This what I changed in the example:
- static void mqtt_app_start(void)
- {
- esp_mqtt_client_config_t mqtt_cfg = {
- // .uri = "ws://test.mosquitto.org:8080/mqtt",
- .host ="192.168.0.12",
- .port =9001,
- };
- I (2627) example_connect: Connected to Vodafone-BC4C
- I (2627) example_connect: IPv4 address: 192.168.0.9
- I (2637) example_connect: IPv6 address: fe80:0000:0000:0000:3e71:bfff:fef0:9b48
- I (2647) MQTTWS_EXAMPLE: Other event id:7
- I (2687) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
- E (2807) MQTT_CLIENT: mqtt_message_receive: received a message with an invalid header=0x48
- E (2807) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
- I (2807) MQTT_CLIENT: Error MQTT Connected
- I (2817) MQTTWS_EXAMPLE: MQTT_EVENT_DISCONNECTED
- I (17817) MQTTWS_EXAMPLE: Other event id:7
- I (17837) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
- E (17937) MQTT_CLIENT: mqtt_message_receive: received a message with an invalid header=0x48
- E (17937) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
- I (17947) MQTT_CLIENT: Error MQTT Connected
- I (17957) MQTTWS_EXAMPLE: MQTT_EVENT_DISCONNECTED