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