Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hglab01/iobroker.tinymqttbroker
This is very tiny MQTT broker which is not managing any objects/states in iobroker but offers a central MQTT broker instance to publish an subscribe topics as MQTT client. Very helpful to let several devices to talk with one broker and interact on iobroker with a MQTT client javascript.
https://github.com/hglab01/iobroker.tinymqttbroker
iobroker mqtt
Last synced: about 2 months ago
JSON representation
This is very tiny MQTT broker which is not managing any objects/states in iobroker but offers a central MQTT broker instance to publish an subscribe topics as MQTT client. Very helpful to let several devices to talk with one broker and interact on iobroker with a MQTT client javascript.
- Host: GitHub
- URL: https://github.com/hglab01/iobroker.tinymqttbroker
- Owner: HGlab01
- License: mit
- Created: 2023-06-16T16:49:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-08T02:46:24.000Z (9 months ago)
- Last Synced: 2024-04-08T03:41:46.071Z (9 months ago)
- Topics: iobroker, mqtt
- Language: TypeScript
- Homepage:
- Size: 760 KB
- Stars: 0
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Logo](admin/tinymqttbroker.png)
# ioBroker.tinymqttbroker![Current version in stable repository](https://iobroker.live/badges/tinymqttbroker-stable.svg)
[![NPM version](https://img.shields.io/npm/v/iobroker.tinymqttbroker.svg)](https://www.npmjs.com/package/iobroker.tinymqttbroker)
[![Downloads](https://img.shields.io/npm/dm/iobroker.tinymqttbroker.svg)](https://www.npmjs.com/package/iobroker.tinymqttbroker)
![Number of Installations](https://iobroker.live/badges/tinymqttbroker-installed.svg)
![Test and Release](https://github.com/HGlab01/ioBroker.tinymqttbroker/workflows/Test%20and%20Release/badge.svg)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FHGlab01%2FioBroker.tinyMQTTbroker.svg?type=shield&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2FHGlab01%2FioBroker.tinyMQTTbroker?ref=badge_shield&issueType=license)[![NPM](https://nodei.co/npm/iobroker.tinymqttbroker.png?downloads=true)](https://nodei.co/npm/iobroker.tinymqttbroker/)
## tinymqttbroker adapter for ioBroker
This is very tiny MQTT broker which is not managing any objects/states in iobroker but offers a central MQTT broker instance to publish an subscribe topics as MQTT client. Very helpful to let several devices to talk with one broker and interact on iobroker with a MQTT client javascript.
**This adapter uses Sentry libraries to automatically report exceptions and code errors to the developers.** For more details and for information how to disable the error reporting see [Sentry-Plugin Documentation](https://github.com/ioBroker/plugin-sentry#plugin-sentry)!
## Requires
* Node.js 18 or higher
* ioBroker host (js-controller) 5.0 or higher## How to use it
A MQTT client could look like
```
const mqtt = require('mqtt');
const protocol = 'mqtt';
const host = 'localhost';
const portClient = 1884;const clientId = `iobroker_mqtt_client_` + Math.floor(Math.random() * 100000 + 100000);
const connectUrl = `${protocol}://${host}:${portClient}`;
const client = mqtt.connect(connectUrl, {
clientId,
clean: true,
connectTimeout: 4000,
reconnectPeriod: 10000
})const topics = ['topic1', 'topic2', 'topic3];
client.on('connect', () => {
client.subscribe(topics, () => {
console.log(`MQTT client says: Connected and subscribe to topics '${topics}'`)
})
})client.on('message', (topic: string, payload) => {
payload = payload.toString();
// deal as you need with topics and payload here
// 'switch' could be helpful
switch (topic) {
case 'topic1':
//your code
break;
case 'topic2':
//your code
break;
})
```For publishing message I use one ioBroker state listening for any changes and pushing it to the broker.
The state expects a JSON with 'topic' and 'message'.
```
on({ id: stateMqttIn, change: 'any' }, function (obj) {
let input: any = obj.state.val;
let topic: string = input.topic;
let message: string = String(input.message);
if (topic && message) client.publish(topic, message);
else log(`MQTT publish not possible with topic '${topic}' and message '${message}'`,'warn');
});
```
IMPORTANT! If you create your own MQTT client in an ioBroker javascript, do not forget to close the client in the scipt by using
```
onStop(function (callback) {
log('MQTT Client will be closed...');
client.end(() => {
if (callback) {
callback();
log('MQTT Client closed');
}
})
}, 2000 /*ms*/);
```## Changelog
### 0.1.3 (2024-10-19)
* (HGlab01) Improve port scan for available ports
* (HGlab01) Improve UI config
* (HGlab01) Bump json-explorer to 0.1.16
* (HGlab01) Bump aedes to 0.51.3### 0.1.1 (2024-02-01)
* (HGlab01) Bump json-explorer to 0.1.15
* (HGlab01) Bump aedes to 0.51.0### 0.1.0 (2023-12-04)
* (HGlab01) first minor release
* (HGlab01) Node.js 18.0 or higher
* (HGlab01) ioBroker host (js-controller) 5.0 or higher### 0.0.8 (2023-10-09)
* (HGlab01) Bump json-explorer to 0.1.14### 0.0.7 (2023-10-05)
* (HGlab01) add logs for "address already in use"-issue### 0.0.6 (2023-09-18)
* (HGlab01) Improve error handling
* (HGlab01) Verify if port is used from other process### 0.0.5 (2023-09-11)
* (HGlab01) add sentry support### 0.0.4(2023-06-30)
* (HGlab01) first release## License
MIT LicenseCopyright (c) 2024 HGlab01
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FHGlab01%2FioBroker.tinyMQTTbroker.svg?type=large&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2FHGlab01%2FioBroker.tinyMQTTbroker?ref=badge_large&issueType=license)