gpio-mock-test-nodejs/action-on-gpio.js

28 lines
617 B
JavaScript

const Gpio = require('onoff').Gpio;
const mqtt = require('mqtt');
const actiontrigger = {
/**
* those arguments should be part of the object
* which should also be mockabke
* @param {onoff.Gpio} gpio
* @param {mqtt.Client} client
*/
pubMqttOnGpio (gpio, client) {
console.log('gpio: ');
if (gpio.readSync() === Gpio.LOW) {
client.publish('button/islow', '{true}', {qos: 1})
}
},
sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
}
module.exports = actiontrigger