User Tools

Site Tools


mqttics

This is an old revision of the document!


Using ICS v9.3

  1. Add IcsMQTTClient component

** if not receiving msg from any subscribe topic, set SSLCLISECURITY to sslclisecnone and AUTOSUBSCRIBE to TRUE

To connect:

  MQTTClient.Host := 'hostname';
  MQTTClient.Port := 1883;
  MQTTClient.Activate (true);

To subscribe:

  mqttclient.Subscribe('topic',qtAT_LEAST_ONCE);

*note, DO NOT subscribe immediately after activate. Give some time first, if want to do almost immediate add this setting in mqttclient:

  mqttclient.AutoSubscribe := true;

To Publish:

   MQTTClient.Publish('topic', msgstring , qtAT_LEAST_ONCE, true);

Taken from ICS demo, to show some info on the connection:

procedure TForm1.btnshowClick(Sender: TObject);
var
  j : integer;
  x : cardinal;
begin
  mmo1.Lines.Add ('');
  mmo1.Lines.Add('------ Client ' + string (MQTTClient.Parser.ClientID) + ' -------');
  mmo1.Lines.Add (format ('Username "%s" Password "%s"', [MQTTClient.Parser.Username, MQTTClient.Parser.Password]));
  mmo1.Lines.Add (format ('Keep Alive "%d" Retry Time "%d" Max Retries "%d"', [MQTTClient.Parser.KeepAlive, MQTTClient.Parser.RetryTime, MQTTClient.Parser.MaxRetries]));
  mmo1.Lines.Add (format ('Will Topic "%s" Message "%s" @ %s', [MQTTClient.Parser.WillTopic, MQTTClient.Parser.WillMessage, QosNames [MQTTClient.Parser.WillQos]]));
  mmo1.Lines.Add ('Subscriptions ----');
  for j := 0 to MQTTClient.Subscriptions.Count - 1 do
    begin
      x := cardinal (MQTTClient.Subscriptions.Objects[j]) and $03;
      if (cardinal (MQTTClient.Subscriptions.Objects[j]) shr 8) and $ff = $ff then
        mmo1.Lines.Add ('  "' + MQTTClient.Subscriptions[j] + '" @ ' + QOSNames[TMQTTQOSType (x)] + ' Acked.')
      else
        mmo1.Lines.Add ('  "' + MQTTClient.Subscriptions[j] + '" @ ' + QOSNames[TMQTTQOSType (x)]);
    end;
end;
mqttics.1732244489.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki