tirolerstefan / kaifa

Read out Kaifa smart meter
MIT License
26 stars 14 forks source link

Implement MQTT export function #12

Closed boredomwontgetus closed 2 years ago

boredomwontgetus commented 2 years ago

Implement a new export function for mqtt brokers. It requires paho-mqtt python module. pip3 install paho-mqtt To activate set the export_format key in your config to MQTT, configure the keys export_mqtt_server, export_mqtt_port, export_mqtt_user,export_mqtt_password and export_mqtt_basetopic to reflect your environment.

Stefan, i am not sure this matches your style- and quality standards but i tried to stay as close to your style as i could. I tested it in my environment and had no problems running it against a mosquitto mqtt server. Please have a look and let me know if you can merge this.

Cheers, Tom

tirolerstefan commented 2 years ago

This is great, thanks!

One thing I would like you to test. I release this script as debian package, so it would be nice to use the debian dependency to the paho mqtt package, so nobody needs to care about installing these dependencies using pip3.

The debian package is called "python3-paho-mqtt", the version in buster is 1.4.0-1. In the pypi repo there is a newer version of paho-mqtt --> 1.6.1 (https://pypi.org/project/paho-mqtt/).

To test whether your code works with 1.4.0, please do the following:

pip3 uninstall paho-mqtt
sudo pip3 uninstall paho-mqtt  # if you installed it as root
sudo apt update
sudo apt install python3-paho-mqtt

Afterwards please check whether it is installed or simply start your script.

Thanks!

boredomwontgetus commented 2 years ago

Sure, i can do this:

$# lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

$# dpkg -l python3-paho-mqtt
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version      Architecture Description
+++-=================-============-============-=================================
ii  python3-paho-mqtt 1.4.0-1      all          MQTT client class (Python 3)
$# 

Works like a charm with 1.4.0 as well.

Tom

boredomwontgetus commented 2 years ago

thank your for merging it. i just found a little problem that occurs when run in SOLARVIEW export with a dummy value for the mqtt broker. i will fork your repo again tomorrow, fix it real quick and file a PR.

boredomwontgetus commented 2 years ago

Managed to fix it right now. See https://github.com/tirolerstefan/kaifa/pull/13