|
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 // |
|
24 |
|
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 ***********************************************************/ |
|
43 |
|
44 |
|
45 // Simple doorbell subscribe client |
|
46 var mqtt = require('mqtt'); |
|
47 var locli = mqtt.connect('mqtt://localhost/'); |
|
48 |
|
49 locli.on('connect', function () { |
|
50 //locli.subscribe('/door/bell'); // explicit |
|
51 //locli.subscribe('/door/#'); // recursive |
|
52 locli.subscribe('/door/+'); // one level |
|
53 }); |
|
54 |
|
55 locli.on('message', function(topic, message) { |
|
56 console.log(message.toString()); |
|
57 //locli.end(); |
|
58 }); |
|
59 |
|
60 // disable automatic reconnect |
|
61 locli.options.reconnectPeriod = 0; |