UNPKG

nixfilter-mqtt

Version:

Filters for publishing and subscribing to MQTT topics, similar to "mosquitto_pub" and "mosquitto_sub"

33 lines (23 loc) 798 B
`#!/usr/bin/env node 'use strict'` # Require the "nixfilter" module nixfilter = require('nixfilter') # Require the "./utils" module utils = require('./utils') # Define the filter and register it on the module nixfilter.filter module, description: 'Subscribe to a MQTT topic and output messages published to the topic' input_reader: null add_arguments: (argument_parser) -> utils.add_common_arguments(argument_parser) argument_parser.addArgument ['subscribe_topic'], help: 'The MQTT topic to subscribe to' return setup: (args) -> utils.connect_to_mqtt_broker(args) .then (@mqtt_client) => @mqtt_client.on 'message', (topic, message) => @output(message) @mqtt_client.subscribe(args.subscribe_topic) terminate: -> utils.disconnect_from_mqtt_broker(@mqtt_client)