Skip to content

Instantly share code, notes, and snippets.

@atimin
Created April 18, 2022 21:00
Show Gist options
  • Save atimin/f6bdff58c308b8c968deaa0b4f519c2f to your computer and use it in GitHub Desktop.
Save atimin/f6bdff58c308b8c968deaa0b4f519c2f to your computer and use it in GitHub Desktop.
mqtt-reduct-writter
const MQTT = require('async-mqtt');
const {Client} = require('reduct-js');
MQTT.connectAsync('tcp://localhost:1883').then(async (mqttClient) => {
await mqttClient.subscribe('mqtt_data');
const reductClient = new Client('http://localhost:8383');
const bucket = await reductClient.getOrCreateBucket('mqtt');
mqttClient.on('message', async (topic, msg) => {
const data = msg.toString();
await bucket.write('mqtt_data', data);
console.log('Received message "%s" from topic "%s" was written', data,
topic);
});
}).catch(error => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment