molobrakos/volvooncall

voc mqtt communication with mosquitto broker.

Closed this issue ยท 7 comments

When trying to publish to a mosquitto broker, login to broker fails.
After trying out several options in the mosquitto_pub configuration file, it looks that
mqtt.py requires secure communication to the broker and it looks also that this function only works with Home Assistant. However https://github.com/arins/voc-to-mqtt works fine, but is not complete and no activity for over a year.
As all the other voc options works fine I would like to swith to native voc mqtt.
Current setup is with latest raspbian and python 3.7.1 on a raspberry pi.
Can this be confirmed? And if so are there easy possibilities to modify the mqtt.py file so that it will work with any broker with and without encryption.

Thanks for an answer in advance

FireWizard52

You can provide url: mqtt://user:password@my.mqtt.broker:1883 in your config for unencrypted communication with a broker.

Thank you for your prompt reply.
I have tested your proposal, but unfortunately no luck.
I have inserted in the file ~/. config/mosquitto_pub url: mqtt://username:password@ ip.ad.dr.ess:1883
This is the only line in the file.
Running ./voc -vv mqtt gives the following output:
19-01-04 21:16.21 DEBUG (MainThread) [asyncio] Using selector: EpollSelector
19-01-04 21:16.21 DEBUG (MainThread) [volvooncall.util] checking for config file ./voc.conf
19-01-04 21:16.21 DEBUG (MainThread) [volvooncall.util] checking for config file ./.voc.conf
19-01-04 21:16.21 DEBUG (MainThread) [volvooncall.util] checking for config file /home/pi/voc.conf
19-01-04 21:16.21 DEBUG (MainThread) [volvooncall.util] checking for config file /home/pi/.voc.conf
19-01-04 21:16.21 INFO (MainThread) [volvooncall.volvooncall] volvooncall.volvooncall 0.8.7 /home/pi/.local/bin/volvooncall/volvooncall.py
19-01-04 21:16.21 DEBUG (MainThread) [volvooncall.volvooncall] Using service https://vocapi.wirelesscar.net/customerapi/rest/v3.0/
19-01-04 21:16.21 DEBUG (MainThread) [volvooncall.volvooncall] User:
Traceback (most recent call last):
File "./voc", line 296, in
run(main(args), debug=debug)
File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 573, in run_until_complete
return future.result()
File "./voc", line 156, in main
return await mqtt.run(connection, credentials)
File "/home/pi/.local/bin/volvooncall/mqtt.py", line 374, in run
mqtt_config = read_mqtt_config()
File "/home/pi/.local/bin/volvooncall/mqtt.py", line 79, in read_mqtt_config
line.replace("-", "").split() for line in f.read().splitlines()
ValueError: dictionary update sequence element #0 has length 3; 2 is required

I have tested several variation of the config,
-url: mqtt://username:password@ ip.ad.dr.ess:1883
--url: mqtt://username:password@ ip.ad.dr.ess:1883
url mqtt://username:password@ ip.ad.dr.ess:1883

Also tried that config in the file ~/.voc.conf, but no luck either.
However running the command:
hbmqtt_pub --url mqtt://ip.ad.dr.ess:1883 -t volvo/volvo -m "Volvo test" runs fine and the message "Volvo test"is received.

Any idea?

Thanks in advance.
FireWizard52

Sorry, I hadn't tested that code path properly, I believe this commit fixes your problem.
a900ad5

Sorry, I hadn't tested that code path properly, I believe this commit fixes your problem.
a900ad5

I have tested this change in my system defining the mqtt_url in ~/.voc.conf and worked fine.

grep mqtt ~/.voc.conf
mqtt_url: mqtt://mqtt:1883

I'm happy to see at least one person satisfied with the change
In my situation it doesn't function.
I added the following line in ~/.voc.conf.
mqtt_url: mqtt://user:password@my.mqtt.broker:1883
The file mosquitto_pub has been deleted from ~/.config.

Running voc -vv mqtt gives the following output:
pi@rpi3plus:~ $ voc -vv mqtt
19-01-14 16:38.05 DEBUG (MainThread) [asyncio] Using selector: EpollSelector
19-01-14 16:38.05 DEBUG (MainThread) [volvooncall.util] checking for config file /home/pi/.local/bin/voc.conf
19-01-14 16:38.05 DEBUG (MainThread) [volvooncall.util] checking for config file /home/pi/.local/bin/.voc.conf
19-01-14 16:38.05 DEBUG (MainThread) [volvooncall.util] checking for config file /home/pi/voc.conf
19-01-14 16:38.05 DEBUG (MainThread) [volvooncall.util] checking for config file /home/pi/.voc.conf
19-01-14 16:38.05 INFO (MainThread) [volvooncall.volvooncall] volvooncall.volvooncall 0.8.7 /home/pi/.local/bin/volvooncall/volvooncall.py
19-01-14 16:38.05 DEBUG (MainThread) [volvooncall.volvooncall] Using service https://vocapi.wirelesscar.net/customerapi/rest/v3.0/
19-01-14 16:38.05 DEBUG (MainThread) [volvooncall.volvooncall] User:
Traceback (most recent call last):
File "/home/pi/.local/bin/voc", line 296, in
run(main(args), debug=debug)
File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 573, in run_until_complete
return future.result()
File "/home/pi/.local/bin/voc", line 154, in main
from volvooncall import mqtt
File "/home/pi/.local/bin/volvooncall/mqtt.py", line 7

^
SyntaxError: invalid syntax

Anyone any idea?

@FireWizard52 have you checked if the mqtt.py is not corrupted ? Try downloading again the files, because it is complaining about syntax error in line 7 but not showing the line contents.

my line 7 from mqtt.py is :

from os.path import join, expanduser

@ivanfmartinez
First my apologies for the somewhat late response.
However you were completely right and probably during the copy process of the new mqtt.py something went wrong and the file was corrupted. At least it didn't look like the mqtt.py file, so even maybe by mistake the wrong file has been copied. You pointed me to the right spot. Thanks.
Just to avoid other issues I decided to make a clean setup with the latest Python 3.7.2.

I can confirm that I configured my mqtt_url in .voc.conf and that it works for me too.

There still exist an issue with honk_and_blink, but therefore I will open a new issue.
I think we can close this one.