diff --git a/config.json b/config.json new file mode 100644 index 0000000..13eb577 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "KEY1": "VALUE1", + "KEY2": "VALUE2" +} \ No newline at end of file diff --git a/framework.yaml b/framework.yaml new file mode 100644 index 0000000..b58a34d --- /dev/null +++ b/framework.yaml @@ -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)에 저장될 저장소 이릅니다. \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..9291447 --- /dev/null +++ b/main.py @@ -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() \ No newline at end of file diff --git a/requirement.txt b/requirement.txt new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/requirement.txt differ