preset fix

This commit is contained in:
2018-04-06 23:38:08 +02:00
parent c503e31ee5
commit a5c629e331
8 changed files with 36 additions and 8 deletions

View File

@ -17,13 +17,15 @@ class MqttHandler {
this.mqttOptions.rejectUnauthorized = true;
}
this.topicHandlers = [];
this.startCallbacks = [];
logger.info("MqttHandler constructed");
}
register(topics, cb) {
register(topics, cb, startCb) {
topics.forEach((topic) => {
this.topicHandlers.push({ topic: topic, callback: cb });
logger.info(`Callback registered for ${topic}`);
});
this.startCallbacks.push(startCb);
}
exec() {
logger.info(`Connecting to ${this.mqttBrokerUrl}`);
@ -39,6 +41,10 @@ class MqttHandler {
logger.info(`${topicHandler.topic} subscribed`);
});
logger.info('MQTT connection established');
this.startCallbacks.forEach((cb) => {
cb();
logger.info("started");
});
});
this.mqttClient.on('message', (topic, payload, packet) => {
if (!packet.retain) {