doorbell/bellhear.js

changeset 0
e8ccd40d0ef6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/doorbell/bellhear.js	Thu Jun 04 14:50:33 2015 +0200
     1.3 @@ -0,0 +1,61 @@
     1.4 +#! /usr/bin/env node
     1.5 +//
     1.6 +//  Doorbell - Door Bell Gateway for Mesh Networks
     1.7 +//  Copyright © 2015 Michael Schloh von Bennewitz <michael@schloh.com>
     1.8 +//
     1.9 +//  Permission to use, copy, modify, and/or distribute this software for
    1.10 +//  any purpose with or without fee is hereby granted, provided that the
    1.11 +//  above copyright notice and this permission notice appear in all copies.
    1.12 +//
    1.13 +//  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
    1.14 +//  WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
    1.15 +//  WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
    1.16 +//  AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
    1.17 +//  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
    1.18 +//  PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
    1.19 +//  ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
    1.20 +//  THIS SOFTWARE.
    1.21 +//
    1.22 +//  This file is part of Doorbell, a smart door bell IoT gateway
    1.23 +//  which can be found at http://dev.europalab.com/doorbell/
    1.24 +//
    1.25 +//  bellhear.js: ECMA JavaScript implementation
    1.26 +//
    1.27 +
    1.28 +/***********************************************************
    1.29 +|              _                  _          _ _           |
    1.30 +|           __| | ___   ___  _ __| |__   ___| | |          |
    1.31 +|          / _` |/ _ \ / _ \| '__| '_ \ / _ \ | |          |
    1.32 +|         | (_| | (_) | (_) | |  | |_) |  __/ | |          |
    1.33 +|          \__,_|\___/ \___/|_|  |_.__/ \___|_|_|          |
    1.34 +|                                                          |
    1.35 +| Requirements: MQTT broker with standard configuration    |
    1.36 +|               NodeJS and NPM modules (see package.json)  |
    1.37 +|                                                          |
    1.38 +| Execute: To start this application, launch it with the   |
    1.39 +|          script named bellhear.js: $ ./bellhear.js       |
    1.40 +|                                                          |
    1.41 +| Support: http://list.europalab.com/mailman/doorbell/     |
    1.42 +|                                                          |
    1.43 +| Test: mosquitto_pub -m ON -t door/bell                   |
    1.44 +|                                                          |
    1.45 +***********************************************************/
    1.46 +
    1.47 +
    1.48 +// Simple doorbell subscribe client
    1.49 +var mqtt = require('mqtt');
    1.50 +var locli = mqtt.connect('mqtt://localhost/');
    1.51 +
    1.52 +locli.on('connect', function () {
    1.53 +    //locli.subscribe('/door/bell');  // explicit
    1.54 +    //locli.subscribe('/door/#');     // recursive
    1.55 +    locli.subscribe('/door/+');       // one level
    1.56 +});
    1.57 + 
    1.58 +locli.on('message', function(topic, message) {
    1.59 +    console.log(message.toString());
    1.60 +    //locli.end();
    1.61 +});
    1.62 +
    1.63 +// disable automatic reconnect
    1.64 +locli.options.reconnectPeriod = 0;

mercurial