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