From be582c10c1200c7b8d42099f0ce23c0cd1de7d21 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 2 Jan 2013 11:12:54 +0100 Subject: [PATCH] Added a basic example for bridging between two topics on MQTT. --- examples/mqtt_topic_bridge.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/mqtt_topic_bridge.js diff --git a/examples/mqtt_topic_bridge.js b/examples/mqtt_topic_bridge.js new file mode 100644 index 0000000..eb5cd3e --- /dev/null +++ b/examples/mqtt_topic_bridge.js @@ -0,0 +1,23 @@ + +var MQTTAscoltatore = require('../').MQTTAscoltatore; +var ascoltatore = new MQTTAscoltatore({ + mqtt: require("mqttjs"), + host: "127.0.0.1", + port: 1883 +}); + +ascoltatore.on("ready", function() { + + ascoltatore.subscribe("sink", function(topic, message) { + console.log(message); + }); + + ascoltatore.subscribe("a/*", function(topic, message) { + ascoltatore.publish("sink", topic + ": " + message); + }); + + ascoltatore.publish("a/g", "hello world"); + ascoltatore.publish("a/f", "hello world"); +}); + +