Sending MQTT messages
Posted: Tue Jun 24, 2025 6:52 pm
Hi, I'm new to this forum and just starting with PureBasic. I would like to send MQTT topic messages from PureBasic and to do that I have to send data in HEX while the SendNetworkString function sends data as string. So I used a HEX() function to convert the values to string. The problem is that I don't see any packets sent out using Wireshark.
Code: Select all
Port = 1883
ConnectionID = OpenNetworkConnection("127.0.0.1", Port)
If ConnectionID
;10 0c 00 04 4d 51 54 54 04 02 00 3c 00 00 hex ;MQTT connect command
;16 12 00 04 77 81 84 84 04 02 00 60 00 00 dec
MQQTMessageString = Hex(16,#PB_Byte)+Hex(12,#PB_Byte)+Hex(00,#PB_Byte)+Hex(04,#PB_Byte)+Hex(77,#PB_Byte)+Hex(81,#PB_Byte)+Hex(84,#PB_Byte)+Hex(84,#PB_Byte)+Hex(04,#PB_Byte)+Hex(02,#PB_Byte)+Hex(00,#PB_Byte)+Hex(60,#PB_Byte)+Hex(00,#PB_Byte)+Hex(00,#PB_Byte)
SendNetworkString(ConnectionID, MQQTMessageString)
CloseNetworkConnection(ConnectionID)
Else
MessageRequester("PureBasic - Client", "Can't find the server (Is it launched ?).", 0)
EndIf