{"id":27120364,"url":"https://github.com/e7217/edgex-add-mqtt-device","last_synced_at":"2026-04-18T19:33:39.459Z","repository":{"id":112643005,"uuid":"395246431","full_name":"e7217/edgex-add-mqtt-device","owner":"e7217","description":"EdgeX 프레임워크 활용하여 가상 디바이스 데이터 수집 및 제어 데모","archived":false,"fork":false,"pushed_at":"2021-08-12T08:26:58.000Z","size":150,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-01T15:46:54.776Z","etag":null,"topics":["edgex","iot","mqtt"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/e7217.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-12T08:18:48.000Z","updated_at":"2021-08-28T08:23:21.000Z","dependencies_parsed_at":"2023-03-09T17:15:23.681Z","dependency_job_id":null,"html_url":"https://github.com/e7217/edgex-add-mqtt-device","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/e7217/edgex-add-mqtt-device","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e7217%2Fedgex-add-mqtt-device","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e7217%2Fedgex-add-mqtt-device/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e7217%2Fedgex-add-mqtt-device/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e7217%2Fedgex-add-mqtt-device/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e7217","download_url":"https://codeload.github.com/e7217/edgex-add-mqtt-device/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e7217%2Fedgex-add-mqtt-device/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31982743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T17:30:12.329Z","status":"ssl_error","status_checked_at":"2026-04-18T17:29:59.069Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["edgex","iot","mqtt"],"created_at":"2025-04-07T09:53:24.770Z","updated_at":"2026-04-18T19:33:39.442Z","avatar_url":"https://github.com/e7217.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create EdgeX Mqtt Device\nlast update 2021.08.09\n* * * \n#### 참고사이트\n+ EdgeX 공식사이트\nhttps://docs.edgexfoundry.org/2.0/examples/Ch-ExamplesAddingMQTTDevice/\n\n+ EdgeX docker builder\n  https://github.com/edgexfoundry/edgex-compose/tree/main/compose-builder\n* * * \n# 설치 \n#### Docker를 이용해 EdgeX 시작\nEdgeX Docker builder를 사용하여 EdgeX 서비스 세트에 대해 정의하고 있는 docker-compose.yml 파일을 생성한다.\n본 데모에서는 v2.0(ireland)를 이용하였다.\n\n```bash\ngit clone -b ireland https://github.com/edgexfoundry/edgex-compose\n```\ndocker-compose 파일을 생성한다. 본 데모에서 정의한 서비스는 다음과 같다. \n+ mqtt-exporter\n+ http-exporter\n+ mqtt-device\n+ http-device\n+ virtual-device\n+ (mqtt-broker) mqtt-device를 활성화하는 경우, 의존성에서 필요로 한다.\n  \n```bash\nmake gen no-secty ds-mqtt ds-rest asc-mqtt asc-http ds-virtual mqtt-broker\n```\n다음과 같은 docker-compose.yml 이 생성된다\n[docker-compose.yml](./docker-compose.yml)\n\n#### MQTT 가상 디바이스 생성\n본 데모의 [mqtt-publisher](mqtt-publisher.py) 및 [mqtt-subscriber](mqtt-subscriber.py)코드로 가상 디바이스를 구성\n\n#### device config 및 device profile 등록\n[device config](custom-config/devices/mqtt.test.device.config.toml) 및 [device profile](custom-config/profiles/mqtt.test.device.profile.yml)을 device-mqtt 환경값 및 볼륨에 매핑\n```yaml\n  device-mqtt:\n    ...\n    environment:\n      ...\n      # custom-config\n      DEVICE_DEVICESDIR: /custom-config/devices\n      DEVICE_PROFILESDIR: /custom-config/profiles\n      MQTTBROKERINFO_HOST: xxx.xxx.xxx.xxx\n      MQTTBROKERINFO_PORT: xxxx\n      ...\n    volumes: \n    - ./custom-config:/custom-config\n```\n\n## 이슈\n##### 1. 네이밍 불일치\n해당 디바이스 네임을 찾지 못할 경우 다음과 같은 이슈가 발생한다\n![그림](screenshot/err01.png)\nconfig.toml 파일의 네이밍을 일치시키니 정상적으로 동작\n```toml\n[[DeviceList]]\n  Name = 'MQTT-Test-Device'\n  ProfileName = 'MQTT-Test-Device-Profile'\n  Description = 'MQTT device is created for test purpose'\n  Labels = [ 'MQTT', 'test' ]\n  [DeviceList.Protocols]\n    [DeviceList.Protocols.mqtt]\n       CommandTopic = 'CommandTopic'\n    [[DeviceList.AutoEvents]]\n       Interval = '30s'\n       OnChange = false\n       SourceName = 'message'\n```\n```python\nimport paho.mqtt.client as mqtt\nfrom paho.mqtt import publish\nimport json, random, time\n\ndataset = {\n    \"name\": \"MQTT-Test-device\",\n    \"cmd\": \"randnum\",\n    \"randnum\": random.randrange(25, 29)\n}\n\nwhile True:\n    time.sleep(2)\n    publish.single(\"DataTopic\", json.dumps(dataset),hostname=\"xxx.xxx.xxx.xxx\", port=xxxx)\n```\n\n##### 2. 값 요청시 Connection refused 응답\n```bash\ncurl http://xxx.xxx.xxx.xxx:59882/api/v2/device/all | json_pp\n\n# error message\ncurl: (7) Failed to connect to xxx.xxx.xxx.xxx port 59882: Connection refused\n```\ndocker-compose.yml의 포트포워딩 부분이 127.0.0.1로 잡혀있어 외부 접속을 막게 됨.\n해당 부분을 수정하면 외부 접속이 가능하다.\n```yaml\n    # 수정 전\n    ports:\n    - 127.0.0.1:5563:5563/tcp\n    - 127.0.0.1:59880:59880/tcp\n\n    # 수정 후\n    ports:\n    - 5563:5563/tcp\n    - 59880:59880/tcp\n```\n##### 3. device에서 해당 리소를 찾을 수 없다는 에러\n```bash\nedgex-device-mqtt          | level=ERROR ts=2021-08-10T03:23:10.230552685Z app=device-mqtt source=managedprofiles.go:129 msg=\"failed to find device MQTT-Test-device in cache\"\nedgex-device-mqtt          | level=ERROR ts=2021-08-10T03:23:10.230596864Z app=device-mqtt source=incominglistener.go:51 msg=\"[Incoming listener] Incoming reading ignored, device resource `randnum` not found from the device `MQTT-Test-device`\"\n```\n디바이스에서 발행하는 메세지의 이름과 EdgeX에 등록된 디바이스의 명칭이 같지 않을 경우 발생.\n```\n# 디바이스로 등록된 이름은 'MQTT-Test-Device'\n\n# published message\n{\n    \"name\": \"MQTT-Test-device\",\n    \"cmd\": \"randnum\",\n    \"method\": \"get\",\n    \"randnum\": round(random.uniform(25, 29), 1)\n}\n```\n위 코드에서 Device가 아닌 device라는 이름으로 보내고 있다. 이를 동일하게 맞춰주면 정상적으로 데이터 수집이 되는 것을 확인할 수 있다.\n```bash\nhttp://{{edgex-host}}:59882/api/v2/device/name/MQTT-Test-Device\n```\n![그림](screenshot/err03.png)\n\n#### 4. 이미 동작하는 중에 config파일들을 수정한다고 바로 반영되지 않는다.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe7217%2Fedgex-add-mqtt-device","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe7217%2Fedgex-add-mqtt-device","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe7217%2Fedgex-add-mqtt-device/lists"}