{"id":18688468,"url":"https://github.com/mycontroller-org/2mqtt","last_synced_at":"2025-10-16T04:53:15.853Z","repository":{"id":57696499,"uuid":"376236613","full_name":"mycontroller-org/2mqtt","owner":"mycontroller-org","description":"MQTT Bridge","archived":false,"fork":false,"pushed_at":"2024-03-30T18:22:02.000Z","size":147,"stargazers_count":25,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T05:36:30.999Z","etag":null,"topics":["bridge","ethernet","home-automation","iot","mqtt-bridge","mycontroller","mysensors","serial"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mycontroller-org.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,"publiccode":null,"codemeta":null}},"created_at":"2021-06-12T08:11:06.000Z","updated_at":"2025-03-20T23:35:59.000Z","dependencies_parsed_at":"2022-09-15T20:50:32.681Z","dependency_job_id":"8af8e31f-a6e0-41df-9b6c-49cd383ab9e5","html_url":"https://github.com/mycontroller-org/2mqtt","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/mycontroller-org/2mqtt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mycontroller-org%2F2mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mycontroller-org%2F2mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mycontroller-org%2F2mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mycontroller-org%2F2mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mycontroller-org","download_url":"https://codeload.github.com/mycontroller-org/2mqtt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mycontroller-org%2F2mqtt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262022941,"owners_count":23246421,"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":["bridge","ethernet","home-automation","iot","mqtt-bridge","mycontroller","mysensors","serial"],"created_at":"2024-11-07T10:36:57.318Z","updated_at":"2025-10-16T04:53:15.847Z","avatar_url":"https://github.com/mycontroller-org.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 2mqtt\n![lint workflow](https://github.com/mycontroller-org/2mqtt/actions/workflows/lint.yaml/badge.svg)\n![publish container images](https://github.com/mycontroller-org/2mqtt/actions/workflows/publish_container_images.yaml/badge.svg)\n![publish executables](https://github.com/mycontroller-org/2mqtt/actions/workflows/publish_executables.yaml/badge.svg)\n\n2mqtt is MQTT bridge. You can convert the serial, ethernet to MQTT\n\n### Supported Providers\n* [MySensors](https://www.mysensors.org/)\n  * `serial` to `MQTT`\n  * `ethernet` to `MQTT`\n* `raw` - sends the serial,ethernet messages to mqtt as is\n  * `serial` to `MQTT`\n  * `ethernet` to `MQTT`\n  * `http` to `MQTT`\n\n## Download\n### Container images\n  * [Docker Hub](https://hub.docker.com/r/mycontroller/2mqtt)\n  * [Quay.io](https://quay.io/repository/mycontroller/2mqtt)\n#### Docker Run\n```bash\ndocker run --detach --name 2mqtt \\\n    --volume $PWD/config.yaml:/app/config.yaml \\\n    --device /dev/ttyUSB0:/dev/ttyUSB0 \\\n    --env  TZ=\"Asia/Kolkata\" \\\n    --restart unless-stopped \\\n    docker.io/mycontroller/2mqtt:1.6\n```\n\n### Download Executables\n* [Released versions](https://github.com/mycontroller-org/2mqtt/releases)\n* [Pre Release](https://github.com/mycontroller-org/2mqtt/releases/tag/development) - `main` branch executables\n\n\n## Configuration\nYou can have more than one adapter configurations\n\nProvider options: `mysensors_v2` and `raw`\n```yaml\nlogger:\n  mode: development         # logger mode: development, production\n  encoding: console         # encoding options: console, json\n  level: info               # log levels: debug, info, warn, error, fatal\n  enable_stacktrace: false  # enable or disable error stack trace\n\nadapters:   # you can have more than one adapter\n  - name: adapter1          # name of the adapter\n    enabled: false          # enable or disable the adapter, default disabled\n    reconnect_delay: 20s    # reconnect automatically, if there is a failure on the connection\n    provider: mysensors_v2  # provider type, options: mysensors_v2, raw\n    source: # source is the device, to be converted to MQTT, based on the type, configurations will be different\n      type: serial              # source device type: serial\n      port: /dev/ttyUSB0        # serial port\n      baud_rate: 115200         # serial baud rate\n      transmit_pre_delay: 10ms  # waits and sends a message, to avoid collision on the source network\n    mqtt: # mqtt broker details\n      broker: tcp://192.168.10.21:1883  # broker url: supports tcp, mqtt, tls, mqtts\n      insecure: false                   # enable/disable insecure on tls connection\n      username:                         # username of the broker\n      password:                         # password of the broker\n      subscribe: in_rfm69/#             # subscribe a topic, should include `#` at the end, your controller to serial port(source)\n      publish: out_rfm69                # publish on this topic, can add many topics with comma, serial to your controller\n      qos: 0                            # qos number: 0, 1, 2\n      transmit_pre_delay: 0s\n      reconnect_delay: 5s\n      connection_timeout: 30s           # mqtt connection timeout (default 30 seconds)\n```\n### Source device configuration\nBased on the source type the configurations will be different.\n#### Serial\n```yaml\nsource:\n  type: serial              # source device type\n  port: /dev/ttyUSB0        # serial port\n  baud_rate: 115200         # serial baud rate\n  transmit_pre_delay: 10ms  # waits and sends a message, to avoid collision on the source network\n  message_splitter: # message splitter byte, default '10'\n```\n#### Ethernet\n```yaml\nsource:\n  type: ethernet                    # source device type\n  server: tcp://192.168.10.21:5003  # ethernet server address with port\n  transmit_pre_delay: 10ms          # waits and sends a message, to avoid collision on the source network\n  message_splitter: # message splitter byte, default '10'\n```\n#### HTTP\n```yaml\nsource:\n  type: http                      # source device type\n  listen_address: \"0.0.0.0:8080\"  # listening address and port\n  is_auth_enabled: true           # enable/disable basic authentication\n  username: hello                 # username of basic authentication\n  password: hello123              # password of basic authentication\n```\nfor http source, on mqtt the payload (json string) will be as follows,\n```json\n{\n  \"method\":\"POST\",\n  \"remoteAddress\":\"192.168.0.1:57112\",\n  \"host\":\"my-secret-host.com:8080\",\n  \"path\":\"/hello\",\n  \"body\":\"say hello\",\n  \"queryParameters\":{\n    \"q1\": [\"v1\"],\n    \"q2\": [\"v1\", \"v2\"]\n  },\n  \"headers\":{\n    \"Accept-Encoding\":[\"gzip\"],\n    \"Cache-Control\":[\"no-cache\"],\n  },\n  \"timestamp\":\"2022-05-27T08:01:55.806281887+05:30\"\n}\n```\n\n---\n### Special note on message_splitter\n*NOTE: Applicable for `serial` and `ethernet` devices*\n* `message_splitter` is a reference char to understand the end of message on serial and ethernet device read\u003cbr\u003e\n* This special char will be included while writing to the device.\n* supports only one char, should be supplied in byte, ie:`0` to `255`, extended ASCII chars\n\n#### Quick references\nFor complete details refer the extended ASCII table \n* `0` - Null char\n* `3` - End of Text\n* `4` - End of Transmission\n* `8` - Back Space\n* `10` - Line Feed\n* `13` - Carriage Return\n\n## Script support\nIn `raw` provider we can add script to support custom specification. If we leave the script part empty, works without formatting.\n\n`2mqtt` support limited `JavaScript` support along with [goja](https://github.com/dop251/goja)\n\n### Configuration file with raw provider and a script support\n```yaml\nlogger:\n  mode: development         # logger mode: development, production\n  encoding: console         # encoding options: console, json\n  level: info               # log levels: debug, info, warn, error, fatal\n  enable_stacktrace: false  # enable or disable error stack trace\n\nadapters:   # you can have more than one adapter\n  - name: adapter1          # name of the adapter\n    enabled: false          # enable or disable the adapter, default disabled\n    reconnect_delay: 20s    # reconnect automatically, if there is a failure on the connection\n    provider: raw  # provider type, options: mysensors_v2, raw\n    source: # source is the device, to be converted to MQTT, based on the type, configurations will be different\n      type: serial              # source device type: serial\n      port: /dev/ttyUSB0        # serial port\n      baud_rate: 115200         # serial baud rate\n      transmit_pre_delay: 10ms  # waits and sends a message, to avoid collision on the source network\n      queue:                  # optional, internal queue config\n        size: 1000            # maximum queue size, default: 1000 (if omitted)\n        retry_enabled: true   # enable/disable retry on failure\n        retry_interval: 1s    # retry interval on failure (starts with 100ms and increases on further retry)\n        retry_max_count: 0    # maximum retry count, 0 means unlimited\n\n    mqtt: # mqtt broker details\n      broker: tcp://192.168.10.21:1883  # broker url: supports tcp, mqtt, tls, mqtts\n      insecure: false                   # enable/disable insecure on tls connection\n      username:                         # username of the broker\n      password:                         # password of the broker\n      subscribe: receive_data/#         # subscribe a topic, should include `#` at the end, your controller to serial port(source)\n      publish: publish_data             # publish on this topic, can add many topics with comma, serial to your controller\n      qos: 0                            # qos number: 0, 1, 2\n      transmit_pre_delay: 0s\n      reconnect_delay: 5s\n      connection_timeout: 30s           # mqtt connection timeout (default 30 seconds)\n      queue:                  # optional, internal queue config\n        size: 1000            # maximum queue size, default: 1000 (if omitted)\n        retry_enabled: true   # enable/disable retry on failure\n        retry_interval: 1s    # retry interval on failure (starts with 100ms and increases on further retry)\n        retry_max_count: 0    # maximum retry count, 0 means unlimited\n\n    formatter_script: # script used to perform custom formatting\n      to_mqtt: |\n        // your multiline javascript\n        // to perform formatting\n        // read examples for more details\n      to_source: |\n        // your multiline javascript\n        // to perform formatting\n        // read examples for more details\n```\n\n### to_mqtt\ndata received from `source` device and posts to `mqtt`. can be `serialPort`, `http`, `ethernet`. for details refer source device options section.\n\nyou will receive the following variables on your script\n* `raw_data` - data received from `source` device\n\nonce the format done, at the end of script, you have to submit the result in two ways \u003cbr\u003e\nin both way, your response should be assigned into `result` variable *WITHOUT* `let`, `var` or `const`. \n1. if you do not want to change the `mqtt` parameters, like `topic`, `QoS`, etc, just assign the response into `result`. example: `result=\"hello\"`\n2. if you need to change `mqtt` parameters dynamically, assign key/value into `result` variable. supported keys,\n  * `data` - your response data should passed on the mqtt publish\n  * `mqtt_topic` - if you want to change the topic dynamically. NOTE: this topic will be appended(suffix) along with global topic (`adapters[].mqtt.publish`)\n  * `mqtt_qos` - you can modify the QoS\n  * `ignore` - if you think, no need to proceed further with this data and do not want to send it to `mqtt` add `ignore: true`. This message will be dropped.\n\n#### examples:\nsimple string return\n```javascript\n// want to append \"_modified\" at the end of raw data\ndata=raw_data + \"_modified\"\n\n// return\nresult=data\n```\n\nreturn as object\n```javascript\n// want to add mqtt topic dynamically\n// assume the raw_data is \"hello;mqtt/secret/topic\"\nconst dataArray = raw_data.split(\";\")\n\n// return\nresult = {\n  data: dataArray[0], // ie: hello\n  mqtt_topic: dataArray[1], // ie: mqtt/secret/topic\n}\n```\n\nignore the data. do not proceed further\n```javascript\n// assume the raw_data is \"ignore_me\"\n\n// ignoreMe is \"true\", if the message is \"ignore_me\"\nconst ignoreMe = raw_data == \"ignore_me\"\n\n// return\nresult = {\n  data: raw_data,\n  ignore: ignoreMe, // is true. this message will not send to mqtt\n}\n```\n\n### to_source\ndata received from `mqtt` passed to formatter script and posts to `source` device.\n\nyou will receive the following variables on your script\n* `raw_data` - data received from mqtt subscription\n* `mqtt_topic` - topic of the received message\n* `mqtt_qos` - qos of the received message\n\nonce the format done, at the end of script, you have to submit the result in two ways \u003cbr\u003e\nin both way, your response should be assigned into `result` variable *WITHOUT* `let`, `var` or `const`. \n1. just assign the into `result`. example: `result=\"hello\"`\n2. assign key/value into `result` variable. supported keys,\n  * `data` - your response data should passed to `source` device\n  * `ignore` - if you think, no need to proceed further with this data and do not want to send it to `source` device add `ignore: true`. This message will be dropped.\n\n#### examples\nsimple string return\n```javascript\n// want to include mqtt topic in the message\n// assume: \n//    raw_data is \"hello\"\n//    mqtt_topic is \"mqtt/secret/topic\"\n\nconst finalData = raw_data + \";\" + mqtt_topic\n\n// return\nresult = finalData // ie: hello;mqtt/secret/topic\n```\n\nreturn as object\n```javascript\n// want to include mqtt topic in the message\n// assume: \n//    raw_data is \"hello\"\n//    mqtt_topic is \"mqtt/secret/topic\"\n\nconst finalData = raw_data + \";\" + mqtt_topic\n\n// return\nresult = {\n  data: finalData, // ie: hello;mqtt/secret/topic\n}\n```\n\nignore the data. do not proceed further\n```javascript\n// assume the raw_data is \"ignore_me\"\n\n// ignoreMe is \"true\", if the message is \"ignore_me\"\nconst ignoreMe = raw_data == \"ignore_me\"\n\n// return\nresult = {\n  data: raw_data,\n  ignore: ignoreMe, // is true. this message will not send to mqtt\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmycontroller-org%2F2mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmycontroller-org%2F2mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmycontroller-org%2F2mqtt/lists"}