Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
|
7d054dd291 | |
|
9ce89eded7 | |
|
4a52837287 |
12
main.py
12
main.py
|
@ -3,8 +3,8 @@ import uuid
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
|
||||||
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
sdtcloudMqttClient = sdtcloudpubsub.sdtcloudpubsub()
|
||||||
mqttClient = sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
sdtcloudMqttClient.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
||||||
|
|
||||||
def read_json_file(file_path):
|
def read_json_file(file_path):
|
||||||
with open(file_path, 'r', encoding='utf-8') as f:
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
|
@ -17,7 +17,7 @@ def extract_data(json_item):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
file_path = '../cnt_data.json'
|
file_path = './cnt_data.json'
|
||||||
items = read_json_file(file_path)
|
items = read_json_file(file_path)
|
||||||
total_count = len(items)
|
total_count = len(items)
|
||||||
index = 0
|
index = 0
|
||||||
|
@ -25,9 +25,9 @@ def main():
|
||||||
while True:
|
while True:
|
||||||
data = extract_data(items[index])
|
data = extract_data(items[index])
|
||||||
if data:
|
if data:
|
||||||
msg = json.dumps(data, ensure_ascii=False, default=str)
|
# msg = json.dumps(data, ensure_ascii=False, default=str)
|
||||||
sdtcloud.pubMessage(mqttClient, msg)
|
sdtcloudMqttClient.pubMessage(data)
|
||||||
print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} Extracted data:{msg}")
|
print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} Extracted data:{data}")
|
||||||
else:
|
else:
|
||||||
print("No 'data' key found in the JSON item.")
|
print("No 'data' key found in the JSON item.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue