smart_garden_server/imports/api/mqttApi.js

13 lines
395 B
JavaScript

import { connect } from 'mqtt';
var client = connect('mqtt://mqtt.timovolkmann.de')
// If connection to the mqtt-client is not established, try to reconnect. Else publish a message to the mqtt broker.
function publish(topic, message) {
if (!client.connected) {
client.reconnect();
}
client.publish(topic, message, () => console.log('message sent...'))
}
module.exports = { publish }