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

MQTT connection with username/password #225

Closed
wifi75 opened this issue Nov 14, 2023 · 17 comments
Closed

MQTT connection with username/password #225

wifi75 opened this issue Nov 14, 2023 · 17 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request MQTT Needs user response
Milestone

Comments

@wifi75
Copy link

wifi75 commented Nov 14, 2023

Hello My weewx send data to my mqt tserver,
my broker have usr and password.
as skyn.conf missing line for set mqtt user and password,
in fact skyn does not connect to mqtt to collect the data and generate the gauge.

image

this is my mqtt sky configurazion

For instructions, see https://github.com/Daveiano/weewx-wdc/wiki/Support-for-weewx-mqtt

[[mqtt]]
    mqtt_websockets_enabled = 1
    mqtt_websockets_host = "192.168.1.52"
    mqtt_websockets_port = 1884
    mqtt_websockets_ssl = 0
    mqtt_websockets_topic = "weather/loop"

How should I add a user and password?

@wifi75 wifi75 added the bug Something isn't working label Nov 14, 2023
@Daveiano Daveiano added documentation Improvements or additions to documentation enhancement New feature or request MQTT and removed bug Something isn't working labels Nov 14, 2023
@Daveiano Daveiano added this to the 3.5.0 milestone Nov 14, 2023
@Daveiano
Copy link
Owner

The skin currently only supports connecting anonymously to the MQTT broker, without a username and password.

I was not aware of people using credentials on the client side, since they are exposed to the public.

I will add this in the next release, please be patient!

@wifi75
Copy link
Author

wifi75 commented Nov 15, 2023

My Broker on Home assistant is configured with user name and password...
ok I will wait for the new version
Thank you

@Daveiano Daveiano changed the title MQTT GAUGE MQTT connection with username/password Nov 18, 2023
Daveiano added a commit that referenced this issue Nov 22, 2023
@wifi75
Copy link
Author

wifi75 commented Nov 22, 2023

hello, how I Can try?

@Daveiano
Copy link
Owner

I released a pre-release, v3.5.0-alpha1, for you to test this out. Please follow the normal update instructions.

You can now set mqtt_websockets_username and mqtt_websockets_password in skin.conf, see https://github.com/Daveiano/weewx-wdc/blob/3.x/skins/weewx-wdc/skin.conf#L45

@Daveiano Daveiano reopened this Nov 22, 2023
@wifi75
Copy link
Author

wifi75 commented Nov 22, 2023

nathing, not working:

image

my broker websocket work on port 1884:

image

on mqtt explorer data it is ok:

image

@Daveiano
Copy link
Owner

Ok, that's difficult for me without something to look at.

Some ideas:

  • You are using a local IP, I assume the skin is hosted in that same network and has access to the specified IP?
  • Do you have any idea which MQTT version you are using (MQTTv3.1.1 vs MQTTv3.1)
  • In the Browser open the Console (via F12 for most browsers, more info here https://screenful.com/guide/how-to/how-to-open-the-browser-developer-console). In the console you should see an error message?

274109325-d9603442-edcb-43bf-b385-b3a21584e9d6

What is the error saying?

@wifi75
Copy link
Author

wifi75 commented Nov 23, 2023

broker have static ip and my broker it is inatalled on Home assistant
https://github.com/home-assistant/addons/tree/master/mosquitto

below my console error
image

@Daveiano
Copy link
Owner

From the screenshot, it looks like you are using secure websockets via SSL (wss://...). Your home assistant config uses non-secure (ws://...) connection on port 1884.

So you should either use

mqtt_websockets_port = 1884
mqtt_websockets_ssl = 0

or

mqtt_websockets_port = 8884
mqtt_websockets_ssl = 1

broker have static ip and my broker it is inatalled on Home assistantbroker have static ip and my broker it is inatalled on Home assistant

Please correct me if I am wrong but the skin has no access to 192.168.1.52! If I am accessing https://meteo.iu3cyv.eu/weewx/ I have no access to YOUR local IP. The only way this could work is when you are accessing the skin in the same network as your Home assistant is operating.

Please let me know if this helps you, you should inform yourself about the differences between Local/Private IPs vs Public IP addresses.

@wifi75
Copy link
Author

wifi75 commented Nov 24, 2023

hello Daveiano nothing you wrote to me is correct,
broker mqtt and meteo weewx server they are on the same local network, weewx reaches the mqtt broker easily!
in the skin configuration I am using the non-secure websocket on port 1884, in fact I configured it like this:
mqtt_websockets_ssl = 0

image

witch this configuration my mqtt explore work !
image

image

@Daveiano
Copy link
Owner

First of all, I just re-configured my MQTT Broker to use a username & password for read access and it works. So the general implementation works.

in the skin configuration I am using the non-secure websocket on port 1884, in fact I configured it like this:
mqtt_websockets_ssl = 0

Perhaps you configured something in weewx.conf ([StdReport][[WdcReport]])? Configurations in weewx.conf have a higher priority than configs in skin.conf. The screenshot clearly proves that your page tries to connect via secure websockets (wss):

GH-225

hello Daveiano nothing you wrote to me is correct,
broker mqtt and meteo weewx server they are on the same local network, weewx reaches the mqtt broker easily!

I think I was not clear about this: It's not weewx, which subscribes to the MQTT broker, it's the browser (the client). Again: If I visit https://meteo.iu3cyv.eu/weewx/, my Browser will have NO access to any of your local IPs. This will only work if you visit the page in the same network as your Broker lives.

@wifi75
Copy link
Author

wifi75 commented Nov 27, 2023

SOrry but what is th correct skin configuration for connect without ssl?

@Daveiano
Copy link
Owner

mqtt_websockets_ssl = 0 should do it. Does it not work?

@wifi75
Copy link
Author

wifi75 commented Nov 28, 2023

mqtt_websockets_ssl = 0 should do it. Does it not work?

in my configuration, as you can see from the screenshots it is already at 0 but I don't understand why it connects to wss from the chrome console..
why do you think?

@Daveiano
Copy link
Owner

Could you please check if there are mqqt skin settings defined in weewx.conf? Like I said in a previous comment:

Perhaps you configured something in weewx.conf ([StdReport][[WdcReport]])?

I did some research and found out that the MQTT Client first tries to connect via the specified protocol (without SSL) and if that fails it tries to connect the other option (with SSl in that case) - so it seems this is normal behaviour because the connection is failing.

Any news on the IPs? My simple guess is that your broker is not reachable by the MQTT Client (Browser).

@wifi75
Copy link
Author

wifi75 commented Nov 30, 2023

my broker can be reached by clients.
in weewx.conf I don't have any mqtt skin configuration.

However, I'm waiting for the new version of homeassistant which will be released at the beginning of December. it seems the current one doesn't accept mqtt websocket. We see....
I will keep you updated

@Daveiano
Copy link
Owner

Ok, good news! Thank you!

@Daveiano
Copy link
Owner

Daveiano commented Feb 3, 2024

@wifi75 Any news on this?

I would like to close this issue. Auth via username/password is included and I don't see any way I can support you further on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request MQTT Needs user response
Projects
None yet
Development

No branches or pull requests

2 participants