|
Post by mauriceatkinson on Jan 11, 2022 3:10:23 GMT -8
|
|
|
Post by Jason on Jan 11, 2022 5:45:08 GMT -8
MQTT is supported out of the box on the SkyWeather2. All you need is a broker to manage the messages and an update to your SkyWeather2 configuration. If you're running the broker on the same RPi as SkyWeather2, simply install Mosquito using sudo apt install mosquitto mosquitto-clients. You can use the defaults for Mosquitto with no issues.
Thanks,
Jason
|
|
|
Post by mauriceatkinson on Jan 15, 2022 11:36:09 GMT -8
I have been tinkering around getting Skyweather2 to connect to Home Assistant and whilst I can see the MQTT messages being received by the MQTT broker these are not imported into its database. I believe that Home Assistant does not allow mqtt anonymous access. My question is whereabouts in skyweather2 do I have the ability to enter the mqtt broker logon id and password?
cheers Maurice
|
|
|
Post by SDL on Jan 16, 2022 11:25:06 GMT -8
Maurice,
Adding password authentication is pretty easy. Take a look at setting up and reconnecting the MQTT server in the code.
BP
|
|
|
Post by mauriceatkinson on Jan 17, 2022 6:04:53 GMT -8
I am obviously doing something wrong as I do not see the broker accepting a new client request from the PI (192.168.1.11) so I am assuming I have not setup password authentication correctly. Could you confirm in which file I need to edit to enter uthe broker username/password?
1642427225: New connection from 192.168.1.11 on port 1883. 1642427225: New client connected from 192.168.1.11 as SkyCam (p2, c1, k60). 1642427225: New connection from 192.168.1.16 on port 1883. {"result": "ok", "data": {}}1642427225: New client connected from 192.168.1.16 as 7BeDbZuzjUFW0Dbl7xRtg5 (p2, c1, k60, u'mqtt01'). 1642427225: New connection from 192.168.1.11 on port 1883. 1642427225: Client SkyCam already connected, closing old connection. 1642427225: New client connected from 192.168.1.11 as SkyCam (p2, c1, k60).
|
|
n7qnm
Junior Member
Posts: 80
|
Post by n7qnm on Jan 17, 2022 16:21:06 GMT -8
Hi, Maurice - the first thing I'd do would be to use mosquitto_sub to make sure you're seeing messages from SkyWeather. you can run it on either the same server as SkyWeaather or really anywhere.
This should show you everything that's getting published. mosquitto_sub -v -h <hostname> -t "#"
To add username and password, you'd probably have to change some code, easiest place would be in publishMQTT.py
Clay N7QNM
|
|
|
Post by mauriceatkinson on Jan 18, 2022 9:57:42 GMT -8
Hi Clay thanks for your suggestion, I have done this already and I can use mosquitto.pub on the raspberry pi with a username and password and can sucessfully send data to the mqtt broker.
I can see skyweather2 sending the data to the mqtt broker but because there is no username and password supplied the broker ignores this (I can see this being received on the broker with mosquitto_sub). This is the problem I want to overcome by getting skyweather2 to include the username and password.
I tried adding to publishMQTT.py but no luck there. I dont want to randomly add stuff to the files as a: it may be the wrong file or b: the structure may be incorrect.
cheers Maurice
|
|
|
Post by Jason on Jan 18, 2022 10:08:36 GMT -8
Can you disable password authentication on the MQTT broker?
Thanks,
Jason
|
|
|
Post by mauriceatkinson on Jan 18, 2022 10:37:57 GMT -8
Not easily and to be honest I dont want to as I will be hosting this on the internet when I have it working.
|
|
|
Post by Jason on Jan 18, 2022 13:43:04 GMT -8
The MQTT client is connected in SkyWeather2.py and passed around through state.py. As a result, I think you need to add the password to the call to connect the MQTT client.
Thanks,
Jason
|
|
|
Post by mauriceatkinson on Jan 18, 2022 14:42:52 GMT -8
Hi Jason excuse my ignorance but where does that mean I need to add the username and password details?
cheers Maurice
|
|
|
Post by Jason on Jan 19, 2022 4:13:29 GMT -8
I'd start with the following line in SkyWeather2.py:
state.mqtt_client.connect(config.MQTT_Server_URL, port=config.MQTT_Port_Number)
Admittedly, I've never setup a secure MQTT broker so am not sure how the authentication parameters get added so you'll need to research that in the paho.mqtt.client documentation.
Thanks,
Jason
|
|
|
Post by mauriceatkinson on Jan 19, 2022 9:18:51 GMT -8
Thanks Jason I have tried several ways of adding - username_pw_set(username=”roger”,password=”password”) to the code in Skyweather2.py but I keep getting the error:
AttributeError: module 'paho.mqtt.client' has no attribute 'username_pw_set'
I have looked in the client.py settings at /usr/local/lib/python3.7/dist-packages/paho/mqtt/ and the 'username_pw_set' is defined
Any ideas?
|
|
|
Post by festeraeb on Jan 19, 2022 12:13:24 GMT -8
|
|
|
Post by mauriceatkinson on Jan 19, 2022 12:31:26 GMT -8
In the interim I have used rtl_433 as this allows a username and password to be sent to the mqtt broker. Using rtl_433 -C si -F "mqtt://<server>:1883,user=<user>,pass=<pass>" allows me to pick up the sensor data from the mqtt broker and currently it is looking OK
If I can make a request for the new version of skyweather2 software...please add the mqtt username and password facility into the skyweatherconfigure web page, it will make sending sensor readings off via mqtt much easier
|
|