ThomDietrich / miflora-mqtt-daemon

Linux service to collect and transfer Xiaomi Mi Flora plant sensor data via MQTT to your smart home system, with cluster support 🌱🌼πŸ₯€πŸ‘🌳
MIT License
610 stars 140 forks source link

After successfull installation and adopting ini i still get this message - no idea how to solve it #91

Closed awiltschek closed 4 years ago

awiltschek commented 4 years ago

He reads all sensors successfully as you see on the first line, but then raises a strange error:

[2019-12-11 14:17:45] Initial connection to Mi Flora sensor "ZamioculcasZamiifolia" (C4:7C:8D:65:FB:48) successful

[2019-12-11 14:17:45] Announcing Mi Flora devices to MQTT broker for auto-discovery ... Traceback (most recent call last): File "./miflora-mqtt-daemon.py", line 256, in mqtt_client.publish('{}/$announce'.format(base_topic), json.dumps(flores_info), retain=True) File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1134, in publish raise ValueError('Publish topic cannot contain wildcards.') ValueError: Publish topic cannot contain wildcards.

rengaboy commented 4 years ago

@ThomDietrich @awiltschek Seems that this project was built using python 3.5, and paho 1.4. You (and me also) are using python 3.7, and paho 1.5, that have differences. @ThomDietrich Is there any chance, that you can rebuild your project, to work in python 3.7 environment?

rengaboy commented 4 years ago

@awiltschek I solved my problem. In my case it was config.ini string with trailing sharp and comment. base_topic = homeassistant # Default for: homeassistant-mqtt should be base_topic = homeassistant

awiltschek commented 4 years ago

this sounds great will try the same as i also have the comment on the end in my config.ini

awiltschek commented 4 years ago

having removed the comment after the config item has solved the problem. so maybe it would help to document this in the README file so that others dont have the same issue. or improve the python program to ignore comments after the config item :-)

ThomDietrich commented 4 years ago

Hey friends, this is weird as comments should be ignored. The line responsible for this logic is:

base_topic = config['MQTT'].get('base_topic', default_base_topic).lower()

This is provided by ConfigParser and should accept and ignore comments. Would you be so kind and insert the following to learn whats going on

print("|{}|".format(base_topic))

What's the output with the original version of the setting?

Thanks!

@rengaboy absolutely. We should switch to 3.7 and the latest Homie version. I am not in a position to take care of this in the next few weeks. Any contribution welcome!!!

awiltschek commented 4 years ago

ok i now added comment and error was here again. then i added your line after the definition of the variable and this was the result,

|miflora # defaul blablabla|

he also read the comment !

i have python 3.7.3 / GCC 8.2.0

i found now the bug.

you need to change the line "config = ConfigParser(delimiters=('=', ))" to "config = ConfigParser(delimiters=('=', ), inline_comment_prefixes=('#'))"

then it worked for me :-)

just had a look at the docu: https://docs.python.org/3/library/configparser.html

ThomDietrich commented 4 years ago

Interesting that we missed this so far! I wonder how many users ran into the error without actually reporting it. Thanks @awiltschek for doing the check.The fix is merged now. @rengaboy feel free to test :)