Question Mqtt Client Written In Abl


19+ years progress programming and still learning.
I'm writing an a MQTT client and I'm getting stuck at the first hurdle. The problem I am having is the MQTT broker is disconnecting the SOCKET connection without any returning any data first.

Here is my code. You should be able to just copy and past the code into your own Progress editor and run it.

What it should do is perform a socket connection, send 10 bytes of data and expecting some data (should be 4 bytes) to be returned. However the server just disconnects????

I guessing the problem is in the Header I send to the MQTT broker but I can't see what the problem is.

define variable connectHeader as memptr no-undo.
define variable connectFlags as integer no-undo.
define variable timethen            as datetime.


set-size(connectHeader) = 0.
set-size(connectHeader) = 10. /** connected Header is 10 bytes in size **/

/** Protocol Name **/
put-byte(connectHeader, 1) = 0x00.
put-byte(connectHeader, 2) = 0x04.
put-byte(connectHeader, 3) = asc('M':U).
put-byte(connectHeader, 4) = asc('Q':U).
put-byte(connectHeader, 5) = asc('T':U).
put-byte(connectHeader, 6) = asc('T':U).

/** Protocol Level **/
put-byte(connectHeader, 7) = 0x04. /** MQTT Version 3.1.1**/

/** Connect Flags **/
put-bits(connectFlags, 8, 1) = 0x01.  /** Username Flag **/
put-bits(connectFlags, 7, 1) = 0x01.  /** Password Flag **/
put-bits(connectFlags, 6, 1) = 0x00.  /** Will Retain **/
put-bits(connectFlags, 4, 2) = 0x01.  /** Will QoS, 2 Bits **/
put-bits(connectFlags, 3, 1) = 0x01.  /** Will Flag **/
put-bits(connectFlags, 2, 1) = 0x01.  /** Clean Session **/
put-bits(connectFlags, 1, 1) = 0x00.  /** Reserved **/

put-byte(connectHeader, 8) = connectFlags.

/** Keep Alive **/
put-byte(connectHeader, 9) = 0x0.
put-byte(connectHeader, 10) = 0x10.

/* PUT-SHORT(connectHeader, 9) = 0x0A. /** 16-bit/2 bytes short word of the number of seconds. A=10**/ */

copy-lob from object connectHeader to file "./connectHeader.txt".

define variable mqttClinet as handle.

CREATE SOCKET mqttClinet .


mqttClinet:connect("-H -S 1883").

if mqttClinet:connected() then
    message "Connected to MQTT server.."
    mqttClinet:write(connectHeader, 1, get-size(connectHeader))     /** write the connect header to the MQTT server **/
timethen = now.

pause 0.5.

define variable packetLength as integer no-undo.


do while mqttClinet:connected():

    packetLength = mqttClinet:get-bytes-available().

    if packetLength  > 0 then
        message packetLength
            view-as alert-box info.
    if absolute( interval(timethen, now, 'seconds') ) ge 10 then
        leave WAIT-FOR-SERVER.


if not mqttClinet:connected() then
    message "Server Disconnected"
        view-as alert-box error.

delete object mqttClinet.

MQTT 3.1.1 technical specifications.
MQTT Version 3.1.1


19+ years progress programming and still learning.
I think I've missing the payload data for it to work correctly.


19+ years progress programming and still learning.
This has become harder than expected. It's combination of interpreting the specifications and cross checking with other languages to get the expected output.


19+ years progress programming and still learning.
I developed a proof of concept of a MQTT client written in the ABL. This project is so in it's infancy that it's no way complete. My objective it to publish messages (XML, JSON, Text, binary etc) from the ABL to a MQTT Broker and have Arduino/ESP32/ESP8266 devices subscribe to these messages and process these messages appropriately.

Future development is to be able to subscribe to 'topics' and receive messages from other MQTT devices via the MQTT broker.

Source code and be found here.
GitHub - Jimbobnz/ABL-MQTT: MQTT ABL Client

MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.


19+ years progress programming and still learning.

So...I thought I would revisit this little project before I start my new job. I've set up an end to end process where my ABL session is publishing a message to an MQTT Server/Broker. I also have an ESP32 with an OLED display which is also persistently connected to the same MQTT server and is subscribing to the same topic as the ABL client is publishing.

So what does this all mean... It means I have the ability to publish a message on the network and have practically any other device or software receiving these messages near real time.

If only I can think of a useful purpose where this would be really handy.

You can use Node.js to handle the MQTT to WebSockets. So, each time a record was updated, an MQTT message could be published and a webpage to be automatically updated as an example.

A bit hard to photograph but here is an example where I am publishing the ISO formatted date every second from the ABL session which is then updating the OLED display. The ABL MQTT CLIENT and the ESP32 are both connected to a common MQTT broker. If you did not know, the ESP32 has built-in WiFi. The ESP32 is connected to my local wifi network.

Last edited: