michael@0: #! /usr/bin/env node michael@0: // michael@0: // Doorbell - Door Bell Gateway for Mesh Networks michael@0: // Copyright © 2015 Michael Schloh von Bennewitz michael@0: // michael@0: // Permission to use, copy, modify, and/or distribute this software for michael@0: // any purpose with or without fee is hereby granted, provided that the michael@0: // above copyright notice and this permission notice appear in all copies. michael@0: // michael@0: // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL michael@0: // WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED michael@0: // WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE michael@0: // AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL michael@0: // DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR michael@0: // PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS michael@0: // ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF michael@0: // THIS SOFTWARE. michael@0: // michael@0: // This file is part of Doorbell, a smart door bell IoT gateway michael@0: // which can be found at http://dev.europalab.com/doorbell/ michael@0: // michael@0: // bellhear.js: ECMA JavaScript implementation michael@0: // michael@0: michael@0: /*********************************************************** michael@0: | _ _ _ _ | michael@0: | __| | ___ ___ _ __| |__ ___| | | | michael@0: | / _` |/ _ \ / _ \| '__| '_ \ / _ \ | | | michael@0: | | (_| | (_) | (_) | | | |_) | __/ | | | michael@0: | \__,_|\___/ \___/|_| |_.__/ \___|_|_| | michael@0: | | michael@0: | Requirements: MQTT broker with standard configuration | michael@0: | NodeJS and NPM modules (see package.json) | michael@0: | | michael@0: | Execute: To start this application, launch it with the | michael@0: | script named bellhear.js: $ ./bellhear.js | michael@0: | | michael@0: | Support: http://list.europalab.com/mailman/doorbell/ | michael@0: | | michael@0: | Test: mosquitto_pub -m ON -t door/bell | michael@0: | | michael@0: ***********************************************************/ michael@0: michael@0: michael@0: // Simple doorbell subscribe client michael@0: var mqtt = require('mqtt'); michael@0: var locli = mqtt.connect('mqtt://localhost/'); michael@0: michael@0: locli.on('connect', function () { michael@0: //locli.subscribe('/door/bell'); // explicit michael@0: //locli.subscribe('/door/#'); // recursive michael@0: locli.subscribe('/door/+'); // one level michael@0: }); michael@0: michael@0: locli.on('message', function(topic, message) { michael@0: console.log(message.toString()); michael@0: //locli.end(); michael@0: }); michael@0: michael@0: // disable automatic reconnect michael@0: locli.options.reconnectPeriod = 0;