Hallo,
glaube vor einigen Monaten schon mal gefragt zu haben, weiss aber leider nicht mehr wo der Beitrag zu finden ist.
Problem:
Ich habe ein Python script, das lauft wunderbar, aber in die .log Datei schreibt es pro sec. bis zu 14x, obwohl das script eigentlich nur alle 60 sec. abgearbeitet wird.
Code
Auszug aus .log
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:13 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:13 gelbw
Woche 12 Do 23.03.2023 16:44:22 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:22 Einspeisung: -220.8 W
Woche 12 Do 23.03.2023 16:44:22 gelbw
Woche 12 Do 23.03.2023 16:44:22 gelbw
Display More
Python
#!/usr/bin/env python3
import logging
import locale
import datetime
import http.client
from influxdb import InfluxDBClient
from socket import socket, AF_INET, SOCK_DGRAM
import time
from time import sleep
while True:
sleep(60)
# Logging
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
logging.basicConfig(filename='/home/pi/th/licht.log', format='%(asctime)s %(message)s', datefmt="Woche %V %a %d.%m.%Y %H:%M:%S",
level=logging.INFO)
# Beispiel eines logs:
if winter and einspeisung >= -1200 and einspeisung < -0 and Ledw_ein:
send_command(ZONE1_ON, IP, PORT)
sleep(0.1)
send_command(Gelb, IP, PORT)
send_command(ZONE1_Dimm, IP, PORT)
logging.info('gelbw') # Logeintrag
# Einspeisung Influx auslesen
client = InfluxDBClient(host='192.168.0.29', port=8086) # ip oder localhost
client.switch_database('zaehler')
results = client.query('SELECT "Gesamtleistung" FROM "AC" GROUP BY* ORDER BY DESC LIMIT 1')
points = results.get_points
point = 0
for point in points():
shelly_eks = point['Gesamtleistung']
einspeisung = shelly_eks
print ((f"Einspeisung: {round (einspeisung, 1)} W"))
logging.info("Einspeisung: %.1f W", einspeisung) # Logeintrag
Display More
Ist da Grundsäzlich was falsch?
Warum loged es pro durchgang nicht nur 1x?
Das script wird mit systemd gestartet und läuft zuverlässig.
Gruss und Danke
gwaag