updated code for chunking and reorganized
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import json, os
|
||||
import json, os, time
|
||||
from datetime import datetime as dt
|
||||
from datetime import timedelta as td
|
||||
from common.Logger import logger
|
||||
@@ -117,8 +117,16 @@ def checkParameterConfig(cfg):
|
||||
return cfg
|
||||
|
||||
|
||||
# Helper function to split the payload into chunks
|
||||
def chunk_payload(payload, chunk_size=20):
|
||||
chunked_values = list(payload["values"].items())
|
||||
for i in range(0, len(chunked_values), chunk_size):
|
||||
yield {
|
||||
"ts": payload["ts"],
|
||||
"values": dict(chunked_values[i:i+chunk_size])
|
||||
}
|
||||
|
||||
def sendData(message, wizard_api):
|
||||
def sendData(message):
|
||||
payload = {"ts": (round(dt.timestamp(dt.now())/600)*600)*1000, "values": {}}
|
||||
resetPayload = {"ts": "", "values": {}}
|
||||
try:
|
||||
@@ -136,7 +144,9 @@ def sendData(message, wizard_api):
|
||||
payload["values"][measure] = message["values"]["hrvalvecontroller"][measure]["raw_data"]
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
publish(__topic__, json.dumps(payload), __qos__, cloud_name="default")
|
||||
for chunk in chunk_payload(payload=payload):
|
||||
publish(__topic__, json.dumps(chunk), __qos__)
|
||||
time.sleep(2)
|
||||
publish("v1/devices/me/attributes", json.dumps({"latestReportTime": (round(dt.timestamp(dt.now())/600)*600)*1000}), __qos__, cloud_name="default")
|
||||
|
||||
if dayReset:
|
||||
|
||||
Reference in New Issue
Block a user