iobroker.tinymqttbroker
v0.1.7
Published
tinymqttbroker
Downloads
328
Readme

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!
Requires
- Node.js 22 or higher
- ioBroker host (js-controller) 6.0.11 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 messages, a dedicated ioBroker state is used that listens for any changes and forwards them to the MQTT broker.
The state expects a JSON payload containing topic and message.
on({ id: stateMqttIn, change: 'any' }, function (obj) {
const input: any = obj.state.val;
const topic: string = input?.topic ?? null;
const message: string = String(input?.message) ?? null;
if (topic && message) client.publish(topic, message);
else log(`MQTT publish not possible for topic '${topic}' and message '${message}'`, 'warn');
});IMPORTANT! If you implement your own MQTT client within an ioBroker JavaScript script, make sure to properly close the client at the end of the script by calling:
onStop(function (callback) {
log('MQTT Client will be closed...');
client.end(() => {
if (callback) {
callback();
log('MQTT Client closed');
}
})
}, 2000 /*ms*/);Changelog
0.1.7 (2026-06-16)
- (copilot) Adapter requires node.js >= 22 now
- (HGlab01) add logs for clientError, connectionError and keepaliveTimeout
- (HGlab01) Bump aedes to 1.0.2
- (HGlab01) code quality improvements
- (HGlab01) dependecy updates
0.1.6 (2026-03-19)
- (HGlab01) Bump aedes to 1.0.1
- (HGlab01) Rename config items
0.1.5 (2026-03-04)
- (HGlab01) Update libs
- (HGlab01) (c) 2026
- (HGlab01) Bump aedes to 1.0.0
0.1.4 (2025-04-22)
- (HGlab01) Improve port scan
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
Older changelogs can be found there
License
MIT License
Copyright (c) 2026 HGlab01 [email protected]
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.

