fp MQTT with user/password support ? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- PaulRowntree · 2018-12-02 04:10 Hi!I have been looking for a Laz/fp MQTT package that will connect to an external MQTT broker; this requires that the package support username and password fields.  The codes that I have seen most often (Delphi ported code by Jamie Ingilby, modified by ZiCog, then modified by heX) [ https://github.com/heX16/mqtt-free- pascal/blob/master/TMQTTClient/MQTT.pas ] does not support these fields, although it looks like some initial code was started in this direction (VariableHeaderConnect ) but not completed and not actually used in the main code. Does anyone know of a functioning fp MQTT package with this capability?  Thanks! ---------------------------------------------------------------------- DonAlfredo · 2018-12-02 09:14 Have a look at the MQTT connect specs: https://www.hivemq.com/blog/mqtt-security-fundamentals-authentication- username-password You see that you can add a username and password into this connection request. Example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FH := FixedHeader(MQTT.CONNECT, 0, 0, 0);VH := VariableHeaderConnect(40);SetLength(Payload, 0);AppendArray(Payload, StrToBytes(FClientID, true));AppendArray(Payload, StrToBytes('username', true));AppendArray(Payload, StrToBytes('password', true));RL := RemainingLength(Length(VH) + Length(Payload));Data := BuildCommand(FH, RL, VH, Payload); ---------------------------------------------------------------------- PaulRowntree · 2018-12-02 22:59 Hi DonAlfredo, and thank you!  Yes, that is the general way to do it. There are also 2 bits that need to be set in the FixedHeader, and I will try this tonight.  Oddly, all versions of the Delphi-forked MQTT code have this in the ReadThread connect code,  //  Build CONNECT message           FH := FixedHeader(MQTT.CONNECT, 0, 0, 0);           VH := VariableHeaderConnect(40);           SetLength(Payload, 0);           AppendArray(Payload, StrToBytes(FClientID, True));           AppendArray(Payload, StrToBytes('lwt', True));                    AppendArray(Payload, StrToBytes(FClientID + ' died', True));           RL := RemainingLength(Length(VH) + Length(Payload));           Data := BuildCommand(FH, RL, VH, Payload); (BOLD sections highlighted by me) It looks like 'lwt' and FClientID+' died' are hard-coded Will topic/message information to be sent if the connection dies.  Does everyone use this same topic/message, or is this a vestigial bit of code? ---------------------------------------------------------------------- PaulRowntree · 2018-12-03 06:46 Setting the special bits, and appending fields as DonAlfredo suggested, works like a charm.  Will share code if anyone is interested.Thanks! ---------------------------------------------------------------------- Anders Gustav · 2019-02-18 20:46 Quote from: PaulRowntree on December 03, 2018, 07:46:47 am... Will share code if anyone is interested.Thanks! Indeed I am! ---------------------------------------------------------------------- Michael Collier · 2025-07-29 12:12 Quote from: PaulRowntree on December 03, 2018, 07:46:47 amSetting the special bits, and appending fields as DonAlfredo suggested, works like a charm.  Will share code if anyone is interested.Thanks! I'm interested in the solution to this I can see where to append fields Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AppendArray(Payload, StrToBytes('username', true));AppendArray(Payload, StrToBytes('password', true)); But not sure about setting 'special bits' can anyone point me to the code for that please? ---------------------------------------------------------------------- cdbc · 2025-07-29 12:31 Hi Saw the title... If you're interested in MQTT, there's a thread HERE, that points to a complete MQTT-Framework written in FPC/Lazarus repo on my GitLab, you could have a look at  Regards Benny