Jump to content
AndrzejBluszcz

Cannot connect IcsMQTTClient to PicoMQTT server

Recommended Posts

I would appreciate an advice on how to connect IcsMQTTClient to PicoMQTT server on ESP8266. The server does not use SSL and serves other clients normally. IcsMQTTClient is trying to connect but with no success. The server reports that an "unknown" client connected and immediately disconnected. The client keeps connecting but nothing changes. 

I am using the Server / Client Demo from v.9.3 with the following properties

  object MQTTClient: TIcsMQTTClient
    ClientID = 'OverbyteClient'
    KeepAlive = 10
    MaxRetries = 8
    RetryTime = 60
    Clean = True
    Broker = False
    AutoSubscribe = False
    Host = '192.168.1.30'
    Port = 1883
    LocalBounce = False
    SslVerifyCerts = False
    SslReportChain = False
    SslRevocation = False
    SslCliSecurity = sslCliSecNone
    OnMon = MQTTClientMon
    OnOnline = MQTTClientOnline
    OnOffline = MQTTClientOffline
    OnEnableChange = MQTTClientEnableChange
    OnFailure = MQTTClientFailure
    OnMsg = MQTTClientMsg
    Left = 150
    Top = 397
  end
 

Should I set some specific options in the client to enable the connection?

Share this post


Link to post

Sorry, no simple answer, the MQTT component was contributed, and only tested against itself.  I don't have any other local MQTT servers to test against, although it was tested against some public servers.  I'm aware there are various versions of MQTT and some servers are non-standard, questionable whether ICS should break the protocol to work with devices that don't follow it, please search back in this forum, I think it's been discussed before.

 

Otherwise, you'll need to use Wireshark or something to see how the other clients are communicating with the server, and change the component to match that.

 

Angus

 

Share this post


Link to post

Thank you for the message.

I have tried to capture the transmissions and it seems that IcsMQTTClient uses MQIsdp protocol (MQTT v.3.1) and the connection request has header flags 0x12 while another client, that connects successfully uses MQTT v.3.1.1 and the header flags 0x10.

The PicoMQTT server uses MQTT v.3.1.1.  

Is there a way to change the behaviour of the IcsMQTTClient? I tried to replace 'MQIsdp' with 'MQTT', but that made things worse. The message is not recognised as MQTT command. 

Andrzej

Share this post


Link to post
Just now, AndrzejBluszcz said:

Thank you for the message.

I have tried to capture the transmissions and it seems that IcsMQTTClient uses MQIsdp protocol (MQTT v.3.1) and the connection request has header flags 0x12 while another client, that connects successfully uses MQTT v.3.1.1 and the header flags 0x10.

The PicoMQTT server uses MQTT v.3.1.1.  

Is there a way to change the behaviour of the IcsMQTTClient? I tried to replace 'MQIsdp' with 'MQTT', but that made things worse. The message is not recognised as MQTT command. 

Andrzej

The packet fixed header byte for "Connect", regardless of 3.1 or 3.11, is 0x10. The lower 4 bits of the packet fixed header are reserved.

The packet fixed header byte for 3.1:

image.thumb.png.5f0db38258e4b00dea4d1315cb2fee51.png

Share this post


Link to post

Sorry no. I do not use it. I would search for the 0x12 ($12), or the text of the protocol name.

Share this post


Link to post

I think it is TIcsMQTTParser.SendConnect procedure. And it makes a header with qtAT_LEAST_ONCE, which is incorrect. I am trying to change it to qtAT_MOST_ONCE and see what happens. 

Andrzej

Share this post


Link to post
Just now, AndrzejBluszcz said:

It is exactly as before with one exception. The header flags are 0x10 now. 

What does that mean? A trace using Wireshark has no response from the broker?

Edited by Mark-

Share this post


Link to post

There is no response from the broker. However the broker fires OnDisconnect event. That is the broker fires OnConnect and OnDisconnect in quick succession. 

Share this post


Link to post
Just now, AndrzejBluszcz said:

There is no response from the broker. However the broker fires OnDisconnect event. That is the broker fires OnConnect and OnDisconnect in quick succession. 

Yeah IIRC, a broker can select to, not answer a connect message or return an error message.

Does the broker documentation state the version(s) or MQTT it supports?

Share this post


Link to post

PicoMQTT supports MQTT version 3.1.1.

IcsMQTTClient supports MQIsdp version 3.1 (MQTT v.3.1).

So the versions on both sides are different and this the only thing that I see at the moment.

Share this post


Link to post

There are a few commercial MQTT clients. Or you could write your own code. The MQTT protocol is not very complicated, by design.

 

Share this post


Link to post
Just now, AndrzejBluszcz said:

OK. Will see.

Thank you for you time and help, Mark.

 

Andrzej

You are welcome.

Share this post


Link to post

I would assume the difference between 3.1 and 3.1.1 is relatively small, so it should be easy to change the ICS component.  But we'd need to know what that difference is, and a server to test against.

 

Angus

 

Share this post


Link to post

I get Connection NOT AUTHORISED connecting to test.mosquitto.org on ports that say unauthenticated, 

 

I'll spend a few minutes looking to see why, but my knowledge of MQTT is zero, and I don't propose to learn the protocol, maintenance of the ICS MQTT component really needs to be done my users that understand and use MQTT. 

 

Angus

 

Share this post


Link to post

I've installed the Mosquitto Broker server locally, and it works OK against the ICS MQTT client.  

 

Our sample currently always adds a default username/password, and this was upsetting test.mosquitto.org on the unauthenticated port, so the sample now allows them to be set specifically, and leaving them blank connects OK to test.mosquitto.org, which is also now on a ComboBox dropdown to make testing easier.

 

But this does not explain why PicoMQTT fails (unless it's also authentication).  Mosquitto supports 3.1, 3.1.1 and 5, I'll see if I can disable 3.1.  There is a comment in the conf file about clients connecting with 3.1.1 and a zero length client Id so the server allocates one, perhaps this explains the difference. 

 

Angus

 

Share this post


Link to post

Thank you for your interest in my case. I am also not an expert in MQTT but at home I run a few little servers and clients on ESP microcontrollers. When I am connecting PicoMQTT client to PicoMQTT server there is no problem. I can also connect MQTT client on my iPhone and a commercial iotMQTTClient. In all cases I have empty usernames and passwords and no SSL. PicoMQTT supports v.3.1.1. 

 

Andrzej

Share this post


Link to post

I'm updating the ICS MQTT client for v3.1.1 at the moment, should be this week.  Not planning v5 at the moment, that is totally different.  Most servers still support 3.1.1.

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×