|
Post by Jason on May 5, 2022 0:57:05 GMT -8
Have you made any changes to how SkyWeather2.py connects to the MQTT broker?
Thanks,
Jason
|
|
|
Post by mauriceatkinson on May 6, 2022 0:53:04 GMT -8
Hi Jason No I havent made any changes in SkyWeather2.py. Below is the mqtt secyion of this file:
import paho.mqtt.client as mqtt
# set up MQTT if (config.MQTT_Enable): state.mqtt_client = mqtt.Client(client_id="SkyWeather2") state.mqtt_client.connect(config.MQTT_Server_URL, port=config.MQTT_Port_Number)
import publishMQTT
|
|
|
Post by Jason on May 6, 2022 3:07:45 GMT -8
Okay cool! Within publishMQTT.py, please add a properly indented print statement within the publish function. Manually run the SkyWeather2.py script for 25 minutes. While the script is running monitor the output and broker using mosquitto_pub when the print statement gets printed to the output. If possible, please capture the script output before and after the print statement appears in the output. If possible, do the same for mosquitto_pub.
Thanks,
Jason
|
|
|
Post by mauriceatkinson on May 6, 2022 9:05:37 GMT -8
hi Jason sorry but confused regarding adding print statement to publishMQTT, could you give me an example?
I installed mosquitto client on the Skyweather pi and ran the following which was received OK on my remote mqtt broker.
sudo mosquitto_pub -h 192.168.1.16 -u user -P passws -t "skyweather2/state" -m "Hello world"
2022-05-06 17:53:37 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on skyweather2/state: b'Hello world'
|
|
|
Post by Jason on May 6, 2022 10:50:15 GMT -8
Hi Jason here is the full publishMQTT.py import config import state import paho.mqtt.client import paho.mqtt.publish as publishMQTT def publish(): if (config.SWDEBUG): print("--->Sending MQTT Packet<---") #state.mqtt_client.publish("skyweather2/state", state.StateJSON) publishMQTT.single("skyweather2/state", state.StateJSON, hostname="192.168.1.16", auth={username:"username", password:"password"}) Looks like you already have a print statement present in the publishMQTT.publish function. I'm looking for the output in the SkyWeather2.py and mosquito_pub that occurs when you see "--->Sending MQTT Packet<---" appear in the output of the SkyWeather2.py script. Thanks, Jason
|
|
|
Post by mauriceatkinson on May 6, 2022 14:08:53 GMT -8
Hi Jason I never see "--->Sending MQTT Packet<---" in the skyweather2py output.
However I do see this error repeated many times: Traceback (most recent call last): File "/home/pi/SDL_Pi_Skyweather2/wirelessSensors.py", line 73, in mqtt_publish_single publishSingle.single(topic, message, hostname = '192.168.1.16') File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/publish.py", line 241, in single protocol, transport, proxy_args) File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/publish.py", line 177, in multiple client.loop_forever() File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1756, in loop_forever rc = self._loop(timeout) File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1164, in _loop rc = self.loop_read() File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1556, in loop_read rc = self._packet_read() File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 2439, in _packet_read rc = self._packet_handle() File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3039, in _packet_handle return self._handle_connack() File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3139, in _handle_connack self, self._userdata, flags_dict, result) File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/publish.py", line 55, in _on_connect raise mqtt.MQTTException(paho.connack_string(rc)) paho.mqtt.MQTTException: Connection Refused: not authorised. Mosquitto not available Connected with result code 5
I also see this error in the skyweather.py output (masked out username and password)
Job "publish (trigger: interval[0:10:00], next run at: 2022-05-06 23:24:41 BST)" raised an exception
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/pi/SDL_Pi_Skyweather2/publishMQTT.py", line 13, in publish
publishMQTT.single("skyweather2/state", state.StateJSON, hostname='192.168.1.16', auth={username:'uuuuu', password:'ppppp'})
NameError: name 'username' is not defined
name 'username' is not defined
File "/usr/local/lib/python3.7/dist-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/pi/SDL_Pi_Skyweather2/publishMQTT.py", line 13, in publish
publishMQTT.single("skyweather2/state", state.StateJSON, hostname='192.168.1.16', auth={username:'uuuuu', password:'ppppp'})
Connected with result code 5
|
|
|
Post by Jason on May 6, 2022 16:18:30 GMT -8
username and password have to be enclosed in quotes. The error above is syntactical. You’ll need to fix that in publishMQTT.py before it will run the code within the script.
Thanks,
Jason
|
|
|
Post by mauriceatkinson on May 7, 2022 11:42:00 GMT -8
I have tried every combination to get the username and password in quotes but I still see conection refused not authorized message.
When the new version of software is released is there any support for MQTT username and password? If so I think I will wait for it to be released as this is getting into the too difficult box
|
|
|
Post by SDL on May 7, 2022 12:57:30 GMT -8
28.0 will support that. You can also remove the password authentication. The latest update to buster broke this.
modify the /etc/mosquitto/mosquitto.conf file and add this to the bottom:
allow_anonymous true
Then reboot your machine. Try it again.
BP
|
|
|
Post by Jason on May 7, 2022 13:54:42 GMT -8
Apologies for not noticing this before, but the auth parameter is expecting a Python dict. That means the key/value pairs should be quoted. auth={‘username’:’<user name>’,’password’:’<password>’} Is your version of publishMQTT.py throwing an exception during import? Thanks, Jason You must quote both the key and value pairs as I did above. You have only quoted the values. Until you do, publishMQTT.py will continue to throw a syntax error! Thanks, Jason
|
|
|
Post by mauriceatkinson on May 19, 2022 9:01:35 GMT -8
I see there was a new version of Skyweather on the 7th May but the issues with mqtt stopping still occur. I can see the data being updated in the Dash app but no data is being transmitted over mqtt. I find it works sometimes after a reboot and then stops, but no amount of reboots make the mqtt data flow again.
Any ideas as to when this issue will be fixed?
|
|
|
Post by SDL on May 25, 2022 19:58:21 GMT -8
Next major upgrade on SkyWeather is being worked on in June. This is one of the issues that is being addressed. Meaning MQTT Reconnection.
BP
|
|