parent
6c0fa469d8
commit
ab447206c2
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"KEY1": "VALUE1",
|
||||||
|
"KEY2": "VALUE2"
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
version: bwc/v2 # bwc 버전 정보입니다.
|
||||||
|
spec:
|
||||||
|
appName: demo_cnt_facility_app # 앱의 이름입니다.
|
||||||
|
appType: common
|
||||||
|
runFile: main.py # 앱의 실행 파일입니다.
|
||||||
|
env:
|
||||||
|
bin: python3 # 앱을 실행할 바이너라 파일 종류입니다.(장비에 따라 다르므로 확인 후 정의해야 합니다.)
|
||||||
|
virtualEnv: demo_cnt_facility_app-env # 사용할 가상환경 이름입니다.
|
||||||
|
package: requirement.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
|
||||||
|
runtime: python3.11.4
|
||||||
|
stackbase:
|
||||||
|
tagName: v1.0.0 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
||||||
|
repoName: demo_cnt_facility_app # Stackbase(gitea)에 저장될 저장소 이릅니다.
|
|
@ -0,0 +1,38 @@
|
||||||
|
import sdtcloudpubsub
|
||||||
|
import uuid
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
|
||||||
|
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
||||||
|
mqttClient = sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
||||||
|
|
||||||
|
def read_json_file(file_path):
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
def extract_data(json_item):
|
||||||
|
data_str = json_item.get('data', None)
|
||||||
|
if data_str:
|
||||||
|
return json.loads(data_str)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def main():
|
||||||
|
file_path = './cnt_data.json'
|
||||||
|
items = read_json_file(file_path)
|
||||||
|
total_count = len(items)
|
||||||
|
index = 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data = extract_data(items[index])
|
||||||
|
if data:
|
||||||
|
msg = json.dumps(data, ensure_ascii=False, default=str)
|
||||||
|
sdtcloud.pubMessage(mqttClient, msg)
|
||||||
|
print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} Extracted data:{msg}")
|
||||||
|
else:
|
||||||
|
print("No 'data' key found in the JSON item.")
|
||||||
|
|
||||||
|
index = (index + 1) % total_count
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Binary file not shown.
Loading…
Reference in New Issue