Use UTC time instead of timestamp

This commit is contained in:
Tanner Collin 2023-01-12 18:32:20 +00:00
parent af87378fd3
commit f01eeacbce

View File

@ -7,13 +7,13 @@ logging.getLogger('aiohttp').setLevel(logging.DEBUG if os.environ.get('DEBUG') e
import asyncio import asyncio
from aiohttp import web from aiohttp import web
from datetime import datetime, timedelta from datetime import datetime, timedelta, timezone
import pytz import pytz
from APSystemsECUR import APSystemsECUR from APSystemsECUR import APSystemsECUR
ECU_IP = '192.168.69.153' ECU_IP = '192.168.69.153'
LISTEN_IP = '192.168.69.100' LISTEN_IP = '192.168.69.106'
ecu = APSystemsECUR(ECU_IP) ecu = APSystemsECUR(ECU_IP)
app = web.Application() app = web.Application()
prev_ecu_timestamp = None prev_ecu_timestamp = None
@ -60,7 +60,7 @@ async def get_data():
if data['timestamp'] != prev_ecu_timestamp: if data['timestamp'] != prev_ecu_timestamp:
total = 0 total = 0
timestamp = datetime.utcnow() utctime = datetime.now(timezone.utc)
for i in data['inverters'].values(): for i in data['inverters'].values():
total += i['power'][0] total += i['power'][0]
@ -73,7 +73,7 @@ async def get_data():
points = [] points = []
for i in data['inverters'].values(): for i in data['inverters'].values():
points.append({ points.append({
'time': timestamp, 'time': utctime,
'measurement': 'inverter', 'measurement': 'inverter',
'tags': {'ecu': data['ecu_id'], 'inverter': i['uid']}, 'tags': {'ecu': data['ecu_id'], 'inverter': i['uid']},
'fields': { 'fields': {
@ -85,7 +85,7 @@ async def get_data():
}) })
points.append({ points.append({
'time': timestamp, 'time': utctime,
'measurement': 'panel', 'measurement': 'panel',
'tags': {'ecu': data['ecu_id'], 'inverter': i['uid'], 'channel': '0'}, 'tags': {'ecu': data['ecu_id'], 'inverter': i['uid'], 'channel': '0'},
'fields': { 'fields': {
@ -96,7 +96,7 @@ async def get_data():
}) })
points.append({ points.append({
'time': timestamp, 'time': utctime,
'measurement': 'panel', 'measurement': 'panel',
'tags': {'ecu': data['ecu_id'], 'inverter': i['uid'], 'channel': '1'}, 'tags': {'ecu': data['ecu_id'], 'inverter': i['uid'], 'channel': '1'},
'fields': { 'fields': {
@ -107,7 +107,7 @@ async def get_data():
}) })
points.append({ points.append({
'time': timestamp, 'time': utctime,
'measurement': 'ecu', 'measurement': 'ecu',
'tags': {'ecu': data['ecu_id']}, 'tags': {'ecu': data['ecu_id']},
'fields': { 'fields': {