Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Gpio = require('onoff').Gpio,
sensor = new Gpio(17, 'in', 'both'); //#A
sensor.watch(function (err, value) { //#B
if (err) exit(err);
console.log(value ? 'there is someone!' : 'not anymore!');
});
function exit(err) {
if (err) console.log('An error occurred: ' + err);
sensor.unexport();
console.log('Bye, bye!')
process.exit();
}
process.on('SIGINT', exit);
// #A Initialize pin 17 in input mode
// #B Listen for state changes on pin 17, if a change is detected the anonymous callback function will be called with the new value
constructor(config) {
super();
this.cols = config.cols || 16; // TODO - Never used, remove?
this.rows = config.rows || 1;
this.largeFont = !!config.largeFont;
this.rs = new Gpio(config.rs, 'low'); // reg. select, output, initially low
this.e = new Gpio(config.e, 'low'); // enable, output, initially low
this.data = config.data.map(gpioNo => new Gpio(gpioNo, 'low'));
this.displayControl = 0x0c; // display on, cursor off, cursor blink off
this.displayMode = 0x06; // left to right, no shift
this.lock = mutexify();
this._init();
}
onAdded() {
this.log('Adding multi: ' + this.getName() + ' (' + this.getData().id + ')');
// 1) Set first capability to true
this.setCapabilityValue('onoff.opt1', true)
.catch( this.error );
// 2) Set capability with TOKEN_NAME to first capability name
console.log('Data is: ' + JSON.stringify(this.getData()));
console.log('State names is: ' + JSON.stringify(this.getData().state_names));
console.log('Setting state to: ' + this.getData().state_names["onoff.opt1"]);
this.setCapabilityValue(TOKEN_NAME, this.getData().state_names["onoff.opt1"])
.catch( this.error );
}
onAdded() {
this.log('Adding multi: ' + this.getName() + ' (' + this.getData().id + ')');
// 1) Set first capability to true
this.setCapabilityValue('onoff.opt1', true)
.catch( this.error );
// 2) Set capability with TOKEN_NAME to first capability name
console.log('Data is: ' + JSON.stringify(this.getData()));
console.log('State names is: ' + JSON.stringify(this.getData().state_names));
console.log('Setting state to: ' + this.getData().state_names["onoff.opt1"]);
this.setCapabilityValue(TOKEN_NAME, this.getData().state_names["onoff.opt1"])
.catch( this.error );
}
// Authorized users, replace with your real IDs
var authorized_users = [
111111111,
];
// Include required libraries
var sensorLib = require('node-dht-sensor');
var Bot = require('node-telegram-bot');
// Initialize relay board (using onoff library)
var Gpio = require('onoff').Gpio,
relay1 = new Gpio(2, 'out'),
relay2 = new Gpio(3, 'out');
// Turn both the relays off
relay1.writeSync(0);
relay2.writeSync(0);
// Initialize DHT11 sensor
sensorLib.initialize(11, 4);
// Initialize and start Telegram BOT (insert your real token)
var bot = new Bot({
token: '0123456789abcdef0123456789abcdef0123456789ab'
});
// Attach event on every received message
bot.on('message', function (message) {
parseMessage(message);
function startMotor (p, time) {
var pin = new Gpio(p, 'out')
pin.writeSync(1);
console.log("writing to " + p.toString() + " for " + time);
setTimeout(function() { stopMotor(pin); }, time);
}
function stopMotor(p) {
LedsPlugin.prototype.connectHardware = function () { //#F
var Gpio = require('onoff').Gpio; //#G
var self = this;
actuator = new Gpio(self.model.values['1'].customFields.gpio, 'out');
console.info('Hardware %s actuator started!', self.model.name);
};
const Gpio = require('onoff').Gpio;
const led = new Gpio(4, 'out');
const button = new Gpio(21, 'in', 'both');
button.watch((err, value) => {
console.log(`value received: ${value}`);
if (err) {
throw err;
}
led.writeSync(value);
});
process.on('SIGINT', () => {
led.unexport();
button.unexport();
});
const config = require('../lib/config.js');
const Gpio = require('onoff').Gpio;
const port = new Gpio(config.GPIO_BUTTON, 'in', 'both');
const Button = require("../devices/button.js")
var button = new Button({
"privateKey": config.PRIVATE_KEY,
"clientCert": config.CLIENT_CERT,
"caCert": config.CA_CERT,
}, config.HOST, config.DEBUG);
button.connect(function(){
port.watch(function (err, value) {
if (err) {
button.logger.error(err);
}
if(value == 1){
button.logger.info('button pressed');
var spawn = require('child_process').spawn;
var url = require('url');
var express = require('express');
var app = express();
var io = require('socket.io').listen(app.listen(3000));
var Gpio = require('onoff').Gpio,
button = new Gpio(25, 'in','both');
var prev_input = 0;
var urlToGetPic="";
var globalSocket = [];
var timeOutHandle;
//this function takes the photo, and sends the url of the photo location through the websocket
function changePhoto() {
var command = spawn(__dirname + '/takePictureLoadtoServer');
var output = [];
command.stdout.on('data', function(chunk) {
output.push(chunk);
});
command.on('close', function(code) {
if (code === 0) {