doorbell/bellpush.js

changeset 0
e8ccd40d0ef6
equal deleted inserted replaced
-1:000000000000 0:00883f6012a1
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 // bellpush.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 bellpush.js: $ ./bellpush.js |
37 | |
38 | Support: http://list.europalab.com/mailman/doorbell/ |
39 | |
40 | Test: mosquitto_sub -t door/bell |
41 | |
42 ***********************************************************/
43
44 // Simple doorbell publish client
45 var mqtt = require('mqtt')
46 var locli = mqtt.connect('mqtt://localhost/');
47 var args = process.argv.slice(2).length; // Argc
48 var prog = process.argv.slice(1)[0]; // Program name
49 var parm = process.argv.slice(2)[0]; // Parameter cmd
50
51 // Either activate or deactivate the doorbell
52 if (args > 1 || parm != 'ON' && parm != 'OFF')
53 console.error('usage: %s <ON|OFF>', prog);
54 else
55 locli.publish('/door/bell', parm);
56
57 // Close connection
58 locli.end();

mercurial