-
Notifications
You must be signed in to change notification settings - Fork 5
feat[auth, client-id]: support username/password authentication; support custom mqtt client ids #9
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
base: master
Are you sure you want to change the base?
Conversation
| %% Start the MQTT client. | ||
| %% | ||
| Config = #{ | ||
| url => "mqtt://mqtt.eclipseprojects.io", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with a working alternative
| init(Config) -> | ||
| try | ||
| Self = self(), | ||
| Port = erlang:open_port({spawn, "atomvm_mqtt_client"}, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
username, password, client_id never made it into the port as they were missing from the opts here.
ca2f793 to
b68dd52
Compare
|
Thank you for raising the issue. This has been broken for a while, but I assumed it was my broker (I was testing on a local broker) that did not the way the authentication was being sent… but as you point out it wasn’t! As a temporary workaround you can add the username and password to the broker URL:
Now that I know this is not just a personal problem, I will work on a proper fix. Thanks again for opening the issue, and please don’t hesitate to open issues for any other problems you encounter, or suggestions for improvements in the AtonVM ecosystem. |
You're welcome @UncleGrumpy - happy to help. |
UncleGrumpy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution! I don't have any maintainer privileges in this repo, but I wanted to leave some comments and suggestions to help speed up the review process when a maintainer gets a chance to review it.
ports/atomvm_mqtt_client.c
Outdated
|
|
||
| // NB. Caller assumes ownership of returned string | ||
| static char *maybe_get_string(term kv, AtomString key, GlobalContext *global) | ||
| static char* maybe_get_string_or_default(term kv, AtomString key, char* default_value, GlobalContext *global) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep consistent with the AtomVM C Coding Style Guide and put the pointer preceding the variable in char *default_value.
| UNUSED(port); | ||
| char *username_str = maybe_get_string(opts, username_atom, global); | ||
| char *password_str = maybe_get_string(opts, password_atom, global); | ||
| // char *cert_str = maybe_get_string(opts, cert_atom, global); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not remove this commented code, left by the original author as a reminder, or at least change it to a TODO: comment to add certificate based authentication.
ports/atomvm_mqtt_client.c
Outdated
| .uri = url_str, | ||
| .username = username_str, | ||
| .password = password_str | ||
| .client_id = client_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
ports/atomvm_mqtt_client.c
Outdated
| .credentials.client_id = client_id | ||
| .credentials = { | ||
| .username = username_str, | ||
| .client_id = client_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
.client_id = client_id, > .client_id = client_id_str,
ports/atomvm_mqtt_client.c
Outdated
| char *username_str = maybe_get_string(opts, username_atom, global); | ||
| char *password_str = maybe_get_string(opts, password_atom, global); | ||
| // char *cert_str = maybe_get_string(opts, cert_atom, global); | ||
| char *client_id = maybe_get_string_or_default(opts, client_id_atom, get_default_client_id(), global); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the naming scheme consistent and use client_id_str here, which would require updating lines 802 and 811 below.
| url => "mqtt://broker.hivemq.com", | ||
| % username => "some-user", % optional | ||
| % password => "some-password", % optional) | ||
| % client_id => "atomvm-client", % optional (generated if missing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default name is atomvm-<DEVICE-MAC-ADDRESS>, so every device will have a unique default name. That may not be the best way of presenting it, but that gives you the idea.
Thanks for the feedback, very much appreciated. I will implement the changes sometime after work. Have a great day @UncleGrumpy |
|
This is going to sound a little nit-picky, but we like to maintain a clean git history for all of the AtomVM repos. I would suggest squashing the two commits (and remove the reference to requested PR changes - nearly every PR gets some small change requested). Optionally, you can separate out the code changes to made in the second commit (addressing PR comments) and flatten those into the first commit, and then have all the typo fixes separated into the second commit and amend the message accordingly. The second is often what would be preferred for the AtomVM repo, but overall this is a small set of changes so either is fine here. |
Not nit-picky at all - I'll squash them ofc. 👍 |
e56f1b8 to
9eb4fce
Compare
…ort custom mqtt client ids; fix documentation typos
Hello!
While playing with AtomVM and this library I made the following observations:
esp_mqtt_client_config_tand never made it into the portclient-idhas no effect (always auto-generated as the value never made it so the port)trusted_certcurrently serves no purpose (never passed into the port)This PR should fix the first two points (tested with self-hosted mosquitto) and removes
trusted_certfor now.Thank you for your great work on AtomVM - love it. ❤️