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.

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

mercurial