This commit is contained in:
Manuel Kamper 2024-03-22 15:26:20 +01:00
parent ca38e29b66
commit a445655c48
1 changed files with 13 additions and 8 deletions

21
main.py
View File

@ -62,15 +62,20 @@ def Reboot():
Logger.LogMessage("Performing Reboot")
machine.reset()
# Calculates the uptime in hours and minutes
# Calculates the uptime in days, hours and minutes
def Uptime():
global boottime
seconds = (time.time() - boottime) % (24 * 3600)
hours = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%d:%02d" % (hours, minutes)
timeDiff = time.time() - boottime
(minutes, seconds) = divmod(timeDiff, 60)
(hours, minutes) = divmod(minutes, 60)
(days,hours) = divmod(hours, 24)
return str(days)+":"+f"{hours:02d}"+":"+f"{minutes:02d}"
#seconds = (time.time() - boottime) % (24 * 3600)
#hours = seconds // 3600
#seconds %= 3600
#minutes = seconds // 60
#seconds %= 60
#return "%d:%02d" % (hours, minutes)
# Reads the onboard temperature sensor's value
def ReadTemp():
@ -259,7 +264,7 @@ async def APIHandling(reader, writer):
elif (req[2] == "current"):
stateis = "current power consumption: " + GetCurrentPower() + " W"
elif (req[2] == "stats"):
stateis = "IP address: " + Networking.GetIPAddress() + "<br>MAC address: " + Networking.GetMACAddress() + "<br>Hostname: " + configs['hostname'] + "<br>API Port: " + str(configs['api_port']) + "<br>Uptime (h:m): " + Uptime() + "<br>Date/Time: " + TimeUtils.DateTimeNow() + "<br>Version: " + version + "<br>GMT Timezone Offset (hours): " + str(configs['gmt_offset']) + "<br>Auto summertime: " + str(configs['auto_summertime']) + "<br>Housekeep logfiles after days: " + str(configs['log_housekeeping_days']) + "<br>CPU frequency (MHz): " + str(machine.freq()/1000000) + "<br>Temperature (&#176;C): " + "%.2f" % temperature + "<br>Powermeter count (kWh): " + GetZaehlerstand() + "<br>Interval to store via API in DB (minutes): " + str(configs['db_api_interval_minutes']) + "<br>Ticks per kWh: " + str(configs['ticks_per_kWh']) + "<br>Current power consumption (W): " + GetCurrentPower() + "<br>Consumption Today (kWh): " + GetTodayConsumption() + "<br>Consumption Yesterday (kWh): " + GetYesterdayConsumption() + "<br>Consumption this week (kWh): " + GetWeekConsumption() + "<br>Consumption last week (kWh): " + GetConsumptionLastWeek() + "<br>Consumption this month (kWh): " + GetConsumptionMonth() + "<br>Consumption last month (kWh): " + GetConsumptionLastMonth() + "<br>Consumption this year (kWh): " + GetConsumptionYear()
stateis = "IP address: " + Networking.GetIPAddress() + "<br>MAC address: " + Networking.GetMACAddress() + "<br>Hostname: " + configs['hostname'] + "<br>API Port: " + str(configs['api_port']) + "<br>Uptime (d:h:m): " + Uptime() + "<br>Date/Time: " + TimeUtils.DateTimeNow() + "<br>Version: " + version + "<br>GMT Timezone Offset (hours): " + str(configs['gmt_offset']) + "<br>Auto summertime: " + str(configs['auto_summertime']) + "<br>Housekeep logfiles after days: " + str(configs['log_housekeeping_days']) + "<br>CPU frequency (MHz): " + str(machine.freq()/1000000) + "<br>Temperature (&#176;C): " + "%.2f" % temperature + "<br>Powermeter count (kWh): " + GetZaehlerstand() + "<br>Interval to store via API in DB (minutes): " + str(configs['db_api_interval_minutes']) + "<br>Ticks per kWh: " + str(configs['ticks_per_kWh']) + "<br>Current power consumption (W): " + GetCurrentPower() + "<br>Consumption Today (kWh): " + GetTodayConsumption() + "<br>Consumption Yesterday (kWh): " + GetYesterdayConsumption() + "<br>Consumption this week (kWh): " + GetWeekConsumption() + "<br>Consumption last week (kWh): " + GetConsumptionLastWeek() + "<br>Consumption this month (kWh): " + GetConsumptionMonth() + "<br>Consumption last month (kWh): " + GetConsumptionLastMonth() + "<br>Consumption this year (kWh): " + GetConsumptionYear()
elif (req[2] == "reboot"):
stateis = "Rebooting device: now..."
Reboot()