Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure MQTT Client Id? #148

Closed
aaamitsingh opened this issue Jun 25, 2018 · 6 comments
Closed

How to configure MQTT Client Id? #148

aaamitsingh opened this issue Jun 25, 2018 · 6 comments
Labels
feature request Feature request

Comments

@aaamitsingh
Copy link

aaamitsingh commented Jun 25, 2018

Some MQTT broker requires "client id" for authentication. In "data/configuration.yaml" there is no any option to enter the Client Id. Can anyone tell me how to pass the Client Id?

# Required: MQTT settings
mqtt:
  # Required: MQTT base topic for zigbee2mqtt MQTT messages
  base_topic: zigbee2mqtt
  # Required: MQTT server URL
  server: 'mqtt://localhost:1883'
  # Optional: MQTT server authentication user
  user: my_user
  # Optional: MQTT server authentication password
  password: my_password
@Koenkk
Copy link
Owner

Koenkk commented Jun 25, 2018

Isn't this just the user:?

@ryanbeaton
Copy link

I did a quick bit of research:

https://stackoverflow.com/questions/27174271/what-is-the-clientid-needed-for
Every MQTT Connection needs a unique client ID. With this unique client ID the broker can recognize when a client reconnects and can close an old potentially half-open TCP connection for the client. Also, the MQTT broker can hold a persistent session for MQTT clients if they desire to do so (cleanSession=false on CONNECT). If you disconnect and reconnect with the same client ID, you will receive all messages for your subscriptions you may have missed and the broker knows your old subscriptions for that client ID.

https://stackoverflow.com/questions/49796461/how-do-i-get-clientid-with-nodered
When the client connects, it sends the clientId, I guess this info is kept somewhere and could be extracted. In IBM bluemix, for example, they manage con add to msg.payload two parameters, DeviceID and deviceType, that are part of the clientId string when connecting.

Sent with GitHawk

Koenkk added a commit that referenced this issue Jun 26, 2018
@Koenkk
Copy link
Owner

Koenkk commented Jun 26, 2018

@ryanbeaton thanks!

I've added support for the MQTT client in branch: https://github.com/Koenkk/zigbee2mqtt/tree/issue_148

You can configure it via:

mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://localhost'
  client_id: 'my_client_id'

@aaamitsingh can you test if it works?

@Koenkk Koenkk added feature request Feature request and removed help wanted labels Jun 26, 2018
@aaamitsingh
Copy link
Author

@ryanbeaton 👍 : Yes you are right and without client_id an MQTT connection cannot be established. Normally broker generates a random client_id for every connection. But some cases where the user needs to validate the client_id or only allow a connection with the prefix client_id there it is mandatory to pass the client_id.

@Koenkk 👍 : Thank you so much for the quick enhancement. Still now I havent used this library I was just checking the configuration that it will support my system or not. So give me some time I will test and let you know the status.

@tb-killa
Copy link
Contributor

@Koenkk
Work great. I can confirm this work as it should.
Please merge it to master or dev and close this branch and Issue.

Koenkk added a commit that referenced this issue Jul 24, 2018
Koenkk added a commit that referenced this issue Jul 24, 2018
Add support for MQTT client ID. #148
@Koenkk
Copy link
Owner

Koenkk commented Jul 24, 2018

Merged and documented: https://github.com/Koenkk/zigbee2mqtt/wiki/Configuration

@Koenkk Koenkk closed this as completed Jul 24, 2018
wilmardo pushed a commit to wilmardo/zigbee2mqtt that referenced this issue Sep 26, 2019
wilmardo pushed a commit to wilmardo/zigbee2mqtt that referenced this issue Sep 26, 2019
wilmardo pushed a commit to wilmardo/zigbee2mqtt that referenced this issue Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

4 participants