{"id":13834498,"url":"https://github.com/oalles/thingsboard-smartgw","last_synced_at":"2025-05-12T16:13:03.149Z","repository":{"id":185963135,"uuid":"670240617","full_name":"oalles/thingsboard-smartgw","owner":"oalles","description":"Some ideas for a custom Thingsboard Gateway based on Redis and Apache Camel java connectors","archived":false,"fork":false,"pushed_at":"2023-09-03T22:08:05.000Z","size":598,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T23:58:01.619Z","etag":null,"topics":["apache-camel","hivemq","hivemq-java-client","mqtt","redis","redis-gears","redis-streams","spring-boot","thingsboard","thingsboard-gateway"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oalles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-07-24T15:45:11.000Z","updated_at":"2025-03-10T03:40:41.000Z","dependencies_parsed_at":"2023-08-12T12:38:20.458Z","dependency_job_id":"757acce3-14fb-43dd-a504-8e3c4d1b0a22","html_url":"https://github.com/oalles/thingsboard-smartgw","commit_stats":null,"previous_names":["oalles/tb-gw-redis","oalles/thingsboard-smartgw"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fthingsboard-smartgw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fthingsboard-smartgw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fthingsboard-smartgw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fthingsboard-smartgw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oalles","download_url":"https://codeload.github.com/oalles/thingsboard-smartgw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253774008,"owners_count":21962198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["apache-camel","hivemq","hivemq-java-client","mqtt","redis","redis-gears","redis-streams","spring-boot","thingsboard","thingsboard-gateway"],"created_at":"2024-08-04T14:00:35.822Z","updated_at":"2025-05-12T16:13:03.069Z","avatar_url":"https://github.com/oalles.png","language":"Java","funding_links":[],"categories":["Integrations"],"sub_categories":["IoT systems"],"readme":"# Thingboard Smart Gateway\n\nIdeas, considerations and POCs for a **custom *Thingsboard Gateway* implementation** as a distributed event driven\napplication based on Redis, Spring Boot 3 and Apache Camel 4.\n\n## Description\n\nWe will show how easily we can implement a custom Thingsboard Gateway application, connecting Hl7v2 messages to\nThingsboard, while having a solution open for future additional complexities.\n\n![TB Smart Gateway diagram](./images/tb-smart-gateway.png)\n\nIt will be comprised of 4 running services: a `Redis` instance and 2 spring boot services: `redisx-mqtt-bridge`,\na `hl7-connector` and a `video-connector`.\n\n## Motivation\n\nYou can read about the motivation for a *Custom Thingsboard Gateway Implementation based on\nRedis* [here](./Motivation.md).\n\n## Features\n\n* Thingsboard Gateway integration.\n* Spring Boot 3 and Apache Camel 4 project configurations.\n* Spring Boot 3 Starter development.\n* Apache Camel HL7v2 camel integration.\n* Spring Data Redis reactive streams.\n* HiveMQ reactive java MQTT client.\n* Apache Camel 4 component development: Video Input Output Component.\n* Deep Java Library (DJL) integration. Yolo 5 detection.\n\n## Modules Description\n\n* [redisx-mqtt-bridge](./redisx-mqtt-bridge): A *service* which connects redis streams and MQTT topics, allowing the\n  seamless transmission of bytes through reactive APIs. It allows us to create\n  a `ThingsBoard Redis Streams Gateway API`.\n* [hl7-connector](./hl7-connector): A Thingsboard Smart Gateway sample connector *service* for HL7v2 messages based on\n  Spring Boot 3 and Apache Camel 4.\n* [thingsboard-smartgw-connector-base](./thingsboard-smartgw-connector-base): A base *library* in order to implement a\n  Thingsboard Smart Gateway java connector. Basically,\n  a `ThingsBoard Redis Streams Gateway API` [publisher](./thingsboard-smartgw-connector-base/src/main/java/es/omarall/thingsboard/smartgw/connector/base/TbSmartGatewayPublisher.java)\n  and some message converter contracts.\n* [thingsboard-smartgw-connector-starter](./thingsboard-smartgw-connector-starter): the Spring Boot starter *library*\n  for the previously described library so a `Thingsboard Smart Gateway Java Connector` may automatically have\n  a `ThingsBoard Redis Streams Gateway API` [publisher](./thingsboard-smartgw-connector-base/src/main/java/es/omarall/thingsboard/smartgw/connector/base/TbSmartGatewayPublisher.java)\n  instantiated and configured.\n* [environment](./environment):\n* [video-connector](./video-connector): A Thingsboard Smart Gateway sample connector *service* for video input and\n  output based on Spring Boot 3 and Apache Camel 4.\n* [camel-video-io](./camel-video-io): An Apache Camel component for video input and output based on javacv library.\n\n## HL7 Scenario\n\nLet's suppose a vital signs monitor device that monitors a patient's vital signs, like breath rate, heart rate and body\ntemperature, by sending HL7v2 ORU-R01 messages to a health information system.\nThe **ORU-R01** (Unsolicited observation result) message in HL7 is used to transmit observations and results, which\ncould include vital signs information, laboratory test results, radiology reports, etc.\n\nThe following is an example of an ORU-R01 message:\n\n```text\nMSH|^~\\\u0026|MonitorDevice|MonitorApp|Hospital|HIS|20230801||ORU^R01|MSG00001|P|2.3|\nPID|1|123456|78901234||Doe^John^^Mr.||19900101|M|||123 Main St.^^City^ST^12345||||S|MRN123456789|1234567890|\nOBR|1|123456|78901234|Vital Signs^Monitor|||20230801103000|||123^Smith^John^Dr.^^^|||||||||||ADM1234567890|20230801103000|\nOBX|1|NM|9279-1^Respiratory rate^LN||20|/min||A|||F|||20230801103000|\nOBX|2|NM|8867-4^Heart rate^LN||80|bpm|||||F|||20230801103000|\nOBX|3|NM|8310-5^Body temperature^LN||37.0|Cel|||||F|||20230801103000|\nOBX|4|NM|9279-1^Respiratory rate^LN||22|/min|||||F|||20230801103500|\nOBX|5|NM|8867-4^Heart rate^LN||85|bpm|||||F|||20230801103500|\nOBX|6|NM|8310-5^Body temperature^LN||37.1|Cel|||||F|||20230801103500|\n```\n\n## Prerequisites\n\n* Docker and docker compose installed on your machine\n* Java 17+\n* Maven 3+ installed\n* A running Thingsboard server or a [Thingsboard Cloud account](https://thingsboard.cloud/) account.\n* A `Gateway device` created in Thingsboard and the device access token copied.\n\n## Getting Started\n\nLet s start cloning the project and deploying the redis instance:\n\n```bash\n$ git clone https://github.com/oalles/thingsboard-smartgw\n$ mvn clean install -DskipTests\n$ cd thingsboard-smartgw/environment\n# Deploy Redis \n$ docker-compose up \n```\n\n### redisx-mqtt-bridge\n\nGiven the following configuration file:\n\n```yaml[redisx-mqtt-bridge/src/main/resources/application.yml] \nmqtt:\n  host: thingsboard.cloud # broker.hivemq.com\n  username: O5iuAs0O1MVFH23lbmL0 # The TB Gateway device access token\n#  password:\n\napplication:\n  bridge-definitions:\n    - name: telemetry \n      direction: REDIS_TO_MQTT\n      streamKey: telemetry # Send telemetry here\n      topic: v1/gateway/telemetry\n    - name: attributes # \n      direction: REDIS_TO_MQTT\n      streamKey: attributes # client attribute updates\n      topic: v1/gateway/attributes\n    - name: attributes updates\n      direction: MQTT_TO_REDIS\n      streamKey: attribute.updates # shared attribute updates on attribute.updates stream\n      topic: v1/gateway/attributes\n```\n\n[redisx-mqtt-bridge](./redisx-mqtt-bridge) allows us to convert\nthe [Thingsboard Mqtt Gateway api](https://thingsboard.io/docs/reference/gateway-mqtt-api/) into a *ThingsBoard Redis\nGateway API*.\n\nRun the [redisx-mqtt-bridge](./redisx-mqtt-bridge) service.\n\n```bash\n$ cd redisx-mqtt-bridge\n$ mvn spring-boot:run\n```\n\n### hl7-connector\n\nThe `HL7 Thingsboard Gateway Connector` is a Spring Boot 3 and Apache Camel 4 project, that will process ORU-R01\nmessages, generating telemetry and client attribute updates.\n\nGiven the following configuration file HL7 Connector\nin [application.yml](./hl7-connector/src/main/resources/application.yml).\n\n```yaml[hl7-connector/src/main/resources/application.yml]\n# This is the endpoint of incoming requests - HL7 Server.\nhl7-server:\n  hostname: localhost\n  port: 8888\n\n# Utility Route - HL7v2 message producer from file definitions\nfile-producer:\n  enabled: true # Enables a utility route\n  input-dir: /tmp/hl7 # Drop HLv2 messages into this folder for testing and development\n  delay-in-seconds: 5\n```\n\nwe are providing a HL7 Server endpoint and a utility route that will read HL7v2 messages from a folder and send them to\nthe HL7 Server endpoint.\n\nRun the [hl7-connector](./hl7-connector) service.\n\n```bash\n$ cd hl7-connector\n$ mvn spring-boot:run\n```\n\n### Usage\n\nYou will find ORU-R01 sample message in [resources folder](./hl7-connector/src/main/resources/oru-r01.txt).\n\n```text\nMSH|^~\\\u0026|MonitorDevice|MonitorApp|Hospital|HIS|20230801||ORU^R01|MSG00001|P|2.3|\nPID|1|123456|78901234||Doe^John^^Mr.||19900101|M|||123 Main St.^^City^ST^12345||||S|MRN123456789|1234567890|\nOBR|1|123456|78901234|Vital Signs^Monitor|||20230801103000|||123^Smith^John^Dr.^^^|||||||||||ADM1234567890|20230801103000|\nOBX|1|NM|9279-1^Respiratory rate^LN||20|/min||A|||F|||20230801103000|\nOBX|2|NM|8867-4^Heart rate^LN||80|bpm|||||F|||20230801103000|\nOBX|3|NM|8310-5^Body temperature^LN||37.0|Cel|||||F|||20230801103000|\nOBX|4|NM|9279-1^Respiratory rate^LN||22|/min|||||F|||20230801103500|\nOBX|5|NM|8867-4^Heart rate^LN||85|bpm|||||F|||20230801103500|\nOBX|6|NM|8310-5^Body temperature^LN||37.1|Cel|||||F|||20230801103500|\n```\n\nJust drop it in `file-producer.input-dir` location. The connector will automatically process the HL7 message and extract\ntelemetry and client attributes updates.\nCheck the Thingsboard console to verify data transmission. A device named `MonitorApp-MonitorDevice` will be created and\ntelemetry and attributes will be updated accordingly.\n\n![HL7 devices](./images/hl7devices.gif)\n\n## UPDATE: Video Scenario\n\nOne common concern when considering Apache Camel for integration is the availability of specific clients or connectors.\nSome might wonder if Apache Camel remains a viable choice when their\ndesired [component](https://camel.apache.org/components/4.0.x/index.html) isn't readily available.\n\nWe 'll explore a hypothetical situation: We need to add a video connector to our gateway to connect to a video source,\nperform person and car detections on each frame, and transmit the results to Thingsboard.\nAll be built on top of Apache Camel.\n\nTo achieve this, we create two components:\n\n* [Video-IO](./camel-video-io) Camel Component: This component facilitates video input and output for Apache Camel.\n* [Video-Connector](./video-connector) for the Gateway: Implemented as a Camel route, this component leverages Yolo V5\n  detections to process video data , relaying the information to Thingsboard.\n\n![Video detections](./images/video-detections.gif)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foalles%2Fthingsboard-smartgw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foalles%2Fthingsboard-smartgw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foalles%2Fthingsboard-smartgw/lists"}