I want to connect to an MQTT broker and recently learned that Unreal has an official MQTT Plugin, which is experimental.
I understand that being experimental means that some things may not work properly, or are subject to change, but the plugin does not seem to work at all. None of the Delegates are fired, whether on Connection, Publish, or Subscription… and connection also simply doesn’t work, with no errors or feedback.
I know the MQTT broker is working since I created a Python script to test it properly.
I was wondering if anyone here has used the official MQTT plugin before, and if/how you were able to work around these issues.
I seem to have found -a- solution though it feels… wrong. It does seem to work though, gets connected then subscribes to the correct topic. Even logs the messages sent to the broker.
I have tried the plugin in 5.3.3, with two different brokers (Mosquitto and NanoMQ), and I can’t get it to connect. The brokers complain about parse errors, so it looks like the protocol isn’t implemented correctly?
Editor Output Log:
LogMQTTCore: Error: Error connecting socket to: 172.104.228.166:1883: SE_EISCONN, Connection state: Connected
LogMQTTCore: Verbose: Abandoning Operations
LogMQTTCore: Warning: Couldn't connect to MQTT server: There was a socket error.
LogMQTTCore: Verbose: Set State to: Connected
I got the built in MQTT plugin to work with the latest Mosquitto (in both blueprints and c++) - but occasionally the plugin will crash the editor seemingly because it receives an unknown packet type from the broker. I traced the issue to the call to MQTT::GetMQTTPacketTypeName on line 570 in MQTTConnection.cpp - this function call crashes
This lookup results in a nullptr if InMessageType does not have an entry in the PacketTypeNames map. Which in turn causes the editor to crash.
I am still exploring why/when this unknown packet is received, and/or modifying the MQTT plugin to better handle this situation.
UPDATE: So the issue arises when calling MqttClientObject->Publish(…) with a FString payload with a certain minimum length. What appears to happen is that the published MQTT packet is also received - and when it is received the packet parser finds a garbage byte that is identical to whatever the last character in the published string is. That results in an erratic/unknown packet type, and the above highlighted code not knowing how to process the incoming packet data. This happens with both NanoMQ and Mosquitto.
UPDATE: The received MQTT message packet seems to drop the last 2 byte(s) of the payload string - so it gets truncated. That explains the garbage byte remaining in the data stream read from the socket.
Solution: In FMQTTPublishPacket::Serialize(FArchive &ar) in the file MQTTOperations.cpp, when deserializing the packet, the calculated payload size is too small. Debugging the code shows that all the raw payload data is actually present in the archive, but due to the error in calculated payload size, all but the last 2 bytes are deserialized. Modifying the magic number in the deserialization code in line 299 from
Would you be able to provide a little more information about your implementation? I’m very new to UE5 or this type of development, in general, but I’m trying to use MQTT in UE5 to use “real-time” data. The blueprint I tried creating a blueprint based on your image, but I keep getting an infinite loop error.
I tried this plugin and it only works in local host with local mosquitto broker in my case.
Anyone knows how to make it work with cloud broker? I tried with hive and got errors.
First error was because the url needs to be an IP address, I did nslookup on the broker url ,used the IP address and now I got different errors like socket error but still doesn’t work. I’ve already tested the broker with python script clients and it’s good.
Thank you all