Created
April 18, 2022 21:00
-
-
Save atimin/f6bdff58c308b8c968deaa0b4f519c2f to your computer and use it in GitHub Desktop.
mqtt-reduct-writter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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