SAIC-iSmart-API / saic-python-mqtt-gateway

MIT License
67 stars 20 forks source link

MQTT Publish topic cannot contain wildcards #99

Closed 5five-5 closed 5 months ago

5five-5 commented 11 months ago
File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1233, in publish
raise ValueError('Publish topic cannot contain wildcards.')
ValueError: Publish topic cannot contain wildcards.

"MQTT_TOPIC" is set to "saic" "HA_DISCOVERY_PREFIX" is set to "homeassistant"

My guess would be "SAIC_USER". Because in my case it contains a "+".

tosate commented 11 months ago

Yes, the SAIC_USER becomes part of the published topics. If it contains a "+" sign, it won't work because in MQTT is a wildcard character with special meaning. We need to implement a bis of logic that removes such special characters from MQTT topics.

tosate commented 10 months ago

The change is available in branch 0.5.0-rc. Maybe you can test it.

5five-5 commented 10 months ago

Unfortunately, I'm not able to test it. On my system I tried to install python3.10, but I have trouble to start the service (I get "no module named 'saic_ismart_client'"). I think the error is on my system, because I tried it with main too, and get the same result. For me it is easier to use a docker image from docker hub, but there is no 0.5.0-rc yet. I'm sorry that my knowledge is not enough to test it.

tosate commented 10 months ago

Actually, it is easy. Go to the directory with the sources and do the following:

python -m venv ./venv  # create virtual environment
./venv/bin/pip install --no-cache-dir -r requirements.txt  # install required packages
./venv/bin/python ./mqtt_gateway.py -m $MQTT_URI -u $SAIC_USER -p $SAIC_PASSWORD  # start gateway
5five-5 commented 10 months ago

Thank you, that did the trick.

I tested it with 0.5.0-rc and Python 3.10, but the error is still the same. (Path has changed since it is on my system now)

File "/home/5five-5/Downloads/saic-python/venv/lib64/python3.10/site-packages/paho/mqtt/client.py", line 1233, in publish
raise ValueError('Publish topic cannot contain wildcards.')
ValueError: Publish topic cannot contain wildcards.
tosate commented 10 months ago

Are you sure that you are in branch 0.5.0-rc and that you are using the latest version? According to my tests, there should be no wildcard characters in the topic.

$ git status
On branch 0.5.0-rc
nothing to commit, working tree clean
$ git pull origin 0.5.0-rc
From github.com:SAIC-iSmart-API/saic-python-mqtt-gateway
 * branch            0.5.0-rc   -> FETCH_HEAD
Already up to date.
5five-5 commented 10 months ago

I haven't git installed on my system. I switched to branch 0.5.0-rc on the github page and then downloaded the .zip archive. If this is not the way to download the branch, I'm sorry. Next weekend I give it another try with git.

nanomad commented 5 months ago

Fixed via PR #214