doorbell/bellhear.js

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rwxr-xr-x

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

     1 #! /usr/bin/env node
     2 //
     3 //  Doorbell - Door Bell Gateway for Mesh Networks
     4 //  Copyright © 2015 Michael Schloh von Bennewitz <michael@schloh.com>
     5 //
     6 //  Permission to use, copy, modify, and/or distribute this software for
     7 //  any purpose with or without fee is hereby granted, provided that the
     8 //  above copyright notice and this permission notice appear in all copies.
     9 //
    10 //  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
    11 //  WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
    12 //  WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
    13 //  AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
    14 //  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
    15 //  PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
    16 //  ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
    17 //  THIS SOFTWARE.
    18 //
    19 //  This file is part of Doorbell, a smart door bell IoT gateway
    20 //  which can be found at http://dev.europalab.com/doorbell/
    21 //
    22 //  bellhear.js: ECMA JavaScript implementation
    23 //
    25 /***********************************************************
    26 |              _                  _          _ _           |
    27 |           __| | ___   ___  _ __| |__   ___| | |          |
    28 |          / _` |/ _ \ / _ \| '__| '_ \ / _ \ | |          |
    29 |         | (_| | (_) | (_) | |  | |_) |  __/ | |          |
    30 |          \__,_|\___/ \___/|_|  |_.__/ \___|_|_|          |
    31 |                                                          |
    32 | Requirements: MQTT broker with standard configuration    |
    33 |               NodeJS and NPM modules (see package.json)  |
    34 |                                                          |
    35 | Execute: To start this application, launch it with the   |
    36 |          script named bellhear.js: $ ./bellhear.js       |
    37 |                                                          |
    38 | Support: http://list.europalab.com/mailman/doorbell/     |
    39 |                                                          |
    40 | Test: mosquitto_pub -m ON -t door/bell                   |
    41 |                                                          |
    42 ***********************************************************/
    45 // Simple doorbell subscribe client
    46 var mqtt = require('mqtt');
    47 var locli = mqtt.connect('mqtt://localhost/');
    49 locli.on('connect', function () {
    50     //locli.subscribe('/door/bell');  // explicit
    51     //locli.subscribe('/door/#');     // recursive
    52     locli.subscribe('/door/+');       // one level
    53 });
    55 locli.on('message', function(topic, message) {
    56     console.log(message.toString());
    57     //locli.end();
    58 });
    60 // disable automatic reconnect
    61 locli.options.reconnectPeriod = 0;

mercurial