Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4975

Python • why is logging not correct, but print is?

$
0
0
Hello,
when I run the script , the print info is correct, but when I look at the logging it is way off and wrong.
Can somebody please have a look at this?


PRINT:
pi@solaranzeige:~/th $ /home/pi/th/probe.py

WP_strom: 1176.18 W
High count: 07:03:29 1
WP_strom: 1174.89 W
High count: 07:04:29 2
WP_strom: 1183.83 W
High count: 07:05:29 3
WP_strom: 1175.84 W
High count: 07:06:29 4
WP_strom: 1183.32 W
High count: 07:07:29 5
WP_strom: 1203.67 W
High count: 07:08:30 6
WP_strom: 1209.47 W
High count: 07:09:30 7
WP_strom: 1214.23 W
High count: 07:10:30 8
Strom_hoch
WP_strom: 1227.23 W
High count: 07:11:30 1

Logging:
Woche 13 Fr 29.03.2024 07:02:04 High count: 07:02:04 4
Woche 13 Fr 29.03.2024 07:02:06 WP_strom: 07:02:06 1155.41 W
Woche 13 Fr 29.03.2024 07:02:06 High count: 07:02:06 4
Woche 13 Fr 29.03.2024 07:02:28 WP_strom: 07:02:28 1168.29 W
Woche 13 Fr 29.03.2024 07:02:28 High count: 07:02:28 4
Woche 13 Fr 29.03.2024 07:03:02 WP_strom: 07:03:02 1167.31 W
Woche 13 Fr 29.03.2024 07:03:02 High count: 07:03:02 3
Woche 13 Fr 29.03.2024 07:03:02 WP_strom: 07:03:02 1167.31 W
Woche 13 Fr 29.03.2024 07:03:02 High count: 07:03:02 4
Woche 13 Fr 29.03.2024 07:03:02 WP_strom: 07:03:02 1171.07 W
Woche 13 Fr 29.03.2024 07:03:02 High count: 07:03:02 2
Woche 13 Fr 29.03.2024 07:03:03 WP_strom: 07:03:03 1171.07 W
Woche 13 Fr 29.03.2024 07:03:03 High count: 07:03:03 5
Woche 13 Fr 29.03.2024 07:03:03 WP_strom: 07:03:03 1164.37 W
Woche 13 Fr 29.03.2024 07:03:03 WP_strom: 07:03:03 1164.37 W
Woche 13 Fr 29.03.2024 07:03:03 High count: 07:03:03 5
Woche 13 Fr 29.03.2024 07:03:03 High count: 07:03:03 5
Woche 13 Fr 29.03.2024 07:03:04 WP_strom: 07:03:04 1167.19 W
Woche 13 Fr 29.03.2024 07:03:04 High count: 07:03:04 5
Woche 13 Fr 29.03.2024 07:03:04 WP_strom: 07:03:04 1167.19 W
Woche 13 Fr 29.03.2024 07:03:04 High count: 07:03:04 5
Woche 13 Fr 29.03.2024 07:03:05 WP_strom: 07:03:04 1167.19 W
Woche 13 Fr 29.03.2024 07:03:05 High count: 07:03:04 5
Woche 13 Fr 29.03.2024 07:03:05 WP_strom: 07:03:04 1167.19 W
Woche 13 Fr 29.03.2024 07:03:05 High count: 07:03:04 5
Woche 13 Fr 29.03.2024 07:03:06 WP_strom: 07:03:06 1172.04 W
Woche 13 Fr 29.03.2024 07:03:06 High count: 07:03:06 5
Woche 13 Fr 29.03.2024 07:03:29 WP_strom: 07:03:29 1176.18 W
Woche 13 Fr 29.03.2024 07:03:29 High count: 07:03:29 5
Woche 13 Fr 29.03.2024 07:03:29 WP_strom: 07:03:29 1176.18 W
Woche 13 Fr 29.03.2024 07:03:29 High count: 07:03:29 1
Woche 13 Fr 29.03.2024 07:04:01 WP_strom: 07:04:01 1205.7 W
Woche 13 Fr 29.03.2024 07:04:01 High count: 07:04:01 1
Woche 13 Fr 29.03.2024 07:04:02 WP_strom: 07:04:02 1205.7 W
Woche 13 Fr 29.03.2024 07:04:02 High count: 07:04:02 4
Woche 13 Fr 29.03.2024 07:04:02 WP_strom: 07:04:02 1198.21 W
Woche 13 Fr 29.03.2024 07:04:02 High count: 07:04:02 2
Woche 13 Fr 29.03.2024 07:04:02 WP_strom: 07:04:02 1198.21 W
Woche 13 Fr 29.03.2024 07:04:02 High count: 07:04:02 5
Woche 13 Fr 29.03.2024 07:04:02 WP_strom: 07:04:02 1198.21 W

Script:

Code:

#!/usr/bin/env python3import sysimport numpy as npimport jsonimport requestsimport loggingimport localeimport http.clientimport datetimefrom datetime import datetimeimport timefrom time import sleepfrom time import strftime# Logginglocale.setlocale(locale.LC_ALL, 'de_DE.utf8')logging.basicConfig(filename='/home/pi/th/test.log', format='%(asctime)s %(message)s', datefmt="Woche %V %a %d.%m.%Y %H:%M:%S",level=logging.INFO)# Überwachung der Leistung für min. x Minutenlow_count = 0high_count = 0while True:    now = datetime.now()    current_time = now.strftime("%H:%M:%S")    r = requests.get(url='http://192.168.0.140/status')    obj = r.json()    WP_strom = obj["emeters"][0]["power"]    print(f"WP_strom: {WP_strom} W")    logging.info(f"WP_strom: {current_time}   {WP_strom} W")    if WP_strom >= 400:        low_count = 0        high_count += 1        print(f"High count: {current_time}   {high_count}")        logging.info(f"High count: {current_time}   {high_count}")        if high_count >= 8:            Stom_hoch = high_count >= 8            print("Strom_hoch")            logging.info("*********** Strom_hoch")        if high_count ==8:            high_count = 0       # if high_count ==8:            Strom_hoch = high_count >= 8    else:        high_count = 0        low_count += 1        print(f"Low count: {current_time}   {low_count}")        logging.info(f"Low count: {current_time}   {low_count}")        if low_count >= 8:            Strom_tief = low_count >= 8            print("Strom_tief")            logging.info("*********** Strom_tief")        if low_count ==8:            low_count = 0      #  if low_count ==8:            Strom_tief = low_count >= 8    sleep(60)

Statistics: Posted by gwaag — Fri Mar 29, 2024 6:34 am



Viewing all articles
Browse latest Browse all 4975

Trending Articles