Adds an MQTT client helper to mojo.js
npm install mojo-plugin-mqtt-helper




A mojo.js plugin to add an MQTT helper, wrapped over mqtt module.
v0.4.0 (09/2024)
- The module does not use async-mqtt anymore, and just returns an MqttClient Object
- As a result, methods subscribe, unsuscribe, publish and end are now blocking methods, so you want to use subscribeAsync, unsuscribeAsync, publishAsync and endAsync instead (please see the examples).
The API is the same as mqtt client.
``javascript
import mojo from '@mojojs/core';
import mqttPlugin from 'mojo-plugin-mqtt-helper';
const app = mojo();
app.plugin(mqttPlugin);
app.get('/', async ctx => {
const client = await ctx.mqttClient('mqtt://test.mosquitto.org');
client.on('message', async (topic, message) => {
await ctx.render({text: Received message on topic ${topic}: ${message}});`
await client.endAsync();
});
await client.subscribeAsync('mojojs/test/#');
await client.publishAsync('mojojs/test/hello/Channel', 'Hello world!');
});
app.start();
This distribution also contains an example implementing a simple websockets based chat room:
chat.
All you need is Node.js 16.0.0 (or newer).
```
$ npm install mojo-plugin-mqtt-helper