budulinek / easy-loxone-influx

Loxone to InfluxDB script using UDP logs
21 stars 7 forks source link

Issue to connect to DB #3

Open loucze opened 1 year ago

loucze commented 1 year ago

02/04/2023 12:32:37 AM File "/usr/src/app/./Loxone2InfluxDB.py", line 176, in 02/04/2023 12:32:37 AM main(host=args.host, port=args.port, ssl=args.ssl, verify=args.verify, debug=args.debug) 02/04/2023 12:32:37 AM File "/usr/src/app/./Loxone2InfluxDB.py", line 151, in main 02/04/2023 12:32:37 AM client.write_points(json_body_log) 02/04/2023 12:32:37 AM File "/usr/local/lib/python3.11/site-packages/influxdb/client.py", line 603, in write_points 02/04/2023 12:32:37 AM return self._write_points(points=points, 02/04/2023 12:32:37 AM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 02/04/2023 12:32:37 AM File "/usr/local/lib/python3.11/site-packages/influxdb/client.py", line 681, in _write_points 02/04/2023 12:32:37 AM self.write( 02/04/2023 12:32:37 AM File "/usr/local/lib/python3.11/site-packages/influxdb/client.py", line 413, in write 02/04/2023 12:32:37 AM self.request( 02/04/2023 12:32:37 AM File "/usr/local/lib/python3.11/site-packages/influxdb/client.py", line 378, in request 02/04/2023 12:32:37 AM raise InfluxDBClientError(err_msg, response.status_code) 02/04/2023 12:32:37 AM influxdb.exceptions.InfluxDBClientError: 401: {"code":"unauthorized","message":"Unauthorized"} 02/04/2023 12:32:37 AM 2023-02-04 00:32:37,806 INFO - Creating InfluxDB client - connection: 192.168.50.10:8086, db: loxone 02/04/2023 12:32:37 AM 2023-02-04 00:32:37,807 INFO - Listening for incoming Loxone UDP packets on 0.0.0.0:2222

budulinek commented 1 year ago

Sorry, I no longer use the python script. The python script is now in "abandonware" category...

PLS use virtual outputs.

P.S. Just an idea... Is your InfluxDB database pasword protected? try to edit the script:

dbuser = os.getenv('INFLUXDB_USER', 'myuser') dbuser_code = os.getenv('INFLUXDB_PASSWORD', 'mypassowrd')

OlofBailey commented 9 months ago

Do you use or plan to use Influx V2? Any changes needed?

budulinek commented 9 months ago

The advantage of InfluxDB 1.8 is that it has a native UDP listener.

There is no native UDP listener in InfluxDB 2 (see also https://github.com/influxdata/influxdb/issues/23483 ) and you need to install and configure Telegraf to receive and process UDP. I have no experience with Telegraf. I was considering upgrading to InfluxDB 2, but eventually decided to stay with 1.8 simply because I do not want to install (maintain and learn how to use) new service (Telegraf) just to receive UDP.

I think it should be possible to configure Telegraf to receive UDP messages. So that you do not need to change anything on the side of Loxone. See:

https://github.com/influxdata/telegraf/blob/master/plugins/inputs/socket_listener/README.md https://github.com/influxdata/telegraf/tree/master/plugins/parsers/influx

If you are successful with Telegraf, let me know and feel free to update this tutorial with pull request!

OlofBailey commented 9 months ago

Thanks so much for your work on this. I've not got it up and running using HTTP for about 30 temp sensors.. I've followed your tutorial to have all 30 statuses feeding into a single http virtual command output...but... I'm only getting one record every 30 seconds for all of the rooms combined.. i.e. I will never get a temp for the kitchen and dining room at once.. I assume you don't have this problem..? Any ideas? Many thanks again! Rich

OlofBailey commented 9 months ago

I tried creating a second Virtual Output command and now I reliably get two values so it seems to be the Virtual Output command that is the bottleneck..

budulinek commented 9 months ago

Do you use this config layout using "Status" blocks? https://github.com/budulinek/easy-loxone-influx/blob/master/2.Virtual%20output.md#4-loxone-config-program

This config layout is supposed to send individual messages (1 per sensor) whenever there is a change at any of the sensor. At least this is how it works for me (with UDP). In this layout, data from different sensors are never combined into one message.

I do not know where the 30s limit is comming from. Try to change "Close connection after sending" in the Virtual output. In Virtual Output Command, set "First Repetition" to 0

Also, could be the case that HTTP Virtual Output has some bottle neck (do not know, I do not use them). UDP Virtual Outputs are very fast.

OlofBailey commented 9 months ago

My suspicion is my issue is with the HTTP connector having a bottleneck but I've not been able to get UDP to work..

But using the UDP connector I'm getting "\u0002" I think it's supposed to signify start of text but I don't know where it's coming from. The difference between my setup and yours is my logic output is Txt.

The 30s limit is coming from my repetition setting..

Feb 10 20:59:51 server1 influxd-systemd-start.sh[18073]: ts=2024-02-10T20:59:51.860433Z lvl=info msg="Failed to parse points" log_id=0nHAVLKl000 service=udp error="unable to parse 'Temperature,room=Office value=23.1\u0002': invalid number"

budulinek commented 9 months ago

\u0002 that is weird...

What do you mean by "logic output is Txt"? Do you use Status block to generate the text? Iff yes, what is your command in Status-text?

OlofBailey commented 9 months ago

Thanks so much for taking a look!

Screenshot 2024-02-10 at 22 12 10 Screenshot 2024-02-10 at 22 12 30 Screenshot 2024-02-10 at 22 14 03 Screenshot 2024-02-10 at 22 13 56 Screenshot 2024-02-10 at 22 14 16

OlofBailey commented 9 months ago

Screenshot 2024-02-10 at 22 15 04

budulinek commented 9 months ago

Nothing suspicious.... UDP virtual output is configured exactly the same way I have.

budulinek commented 9 months ago

No ideay where that \u0002 is comming from... ....maybe a workaround? In Status block, change the Status-text and insert additional space at the end of the command, so that you will have: <vn> value=<v1.1> Maybe with space (and not \u0002) after the value, the InfluxDB parser will accept (parse) the message?

Minor thing: for sensors I would recommend "Value on timeout": Retain last value

OlofBailey commented 9 months ago

Thanks so much. I'm afraid I tried that already as well as escaping characters. It just ends up trying to interpret it as a timestamp.. Feb 10 22:51:47 server1 influxd-systemd-start.sh[18073]: ts=2024-02-10T22:51:47.150269Z lvl=info msg="Failed to parse points" log_id=0nHAVLKl000 service=udp error="unable to parse 'Temperature,room=Office value=23.0 ignore=\u0002': bad timestamp"

Thanks for the input, we have had some issues with the Modbus sensors and Loxone buffers so we went with a fixed number that would be obvious in the UK..