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

config load error #84

Open arossmann opened 5 years ago

arossmann commented 5 years ago

when I run the python script, I get this error: Traceback (most recent call last): File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 126, in reporting_mode = config['General'].get('reporting_method', 'mqtt-json') File "/usr/lib/python3.5/configparser.py", line 956, in getitem raise KeyError(key) KeyError: 'General'

What am I doing wrong?

my config is this:

# Configuration file for Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
# Source: https://github.com/ThomDietrich/miflora-mqtt-daemon
#
# Uncomment and adapt all settings as needed.
[General]
reporting_method = mqtt-json
adapter = hci0
[Daemon]
enabled = true
period = 300
[MQTT]
hostname = localhost
port = 1883
keepalive = 60
base_topic = miflora                   # Default for: mqtt-json, mqtt-smarthome
homie_device_id = miflora-mqtt-daemon
# The MQTT broker authentification credentials (Default: no authentication)
#username = user
#password = pwd123
# Enable TLS/SSL on the connection
tls = false
# Path to CA Certificate file to verify host
#tls_ca_cert =
# Path to TLS client auth key file
#tls_keyfile =
# Path to TLS client auth certificate file
#tls_certfile =
[Sensors]
BonsaiKitchen = C4:XXXXXXX # real mac address to be inserted
arossmann commented 5 years ago

ERROR 40 <-- my fault. it couldn't find the config file

ThomDietrich commented 5 years ago

Happy for you you fixed the issue. I think it's worth catching the error. Would you like to propose a PR?

Also see: https://stackoverflow.com/a/18091313/6654920

And my suggestion on how to react:

https://github.com/ThomDietrich/miflora-mqtt-daemon/blob/c4aae6ec9bbccdb58cac813e5e6cd1422e78b1dc/miflora-mqtt-daemon.py#L151-L152

arossmann commented 5 years ago

Happy for you you fixed the issue. I think it's worth catching the error. Would you like to propose a PR?

Also see: https://stackoverflow.com/a/18091313/6654920

And my suggestion on how to react:

https://github.com/ThomDietrich/miflora-mqtt-daemon/blob/c4aae6ec9bbccdb58cac813e5e6cd1422e78b1dc/miflora-mqtt-daemon.py#L151-L152

As I ran in the same situation (but was aware of the missing config g), a suitable error message would be better. I'll create one