Tentative test for control toggle

This commit is contained in:
Skylar Grant 2024-08-21 22:02:23 -04:00
parent 5fa3d5bb9c
commit a987800cd7
2 changed files with 13 additions and 1 deletions

View File

@ -79,6 +79,11 @@ module.exports = {
console.log(`Message received on topic ${topic}: ${msgStr}`);
console.log(msgJson);
state[msgJson.name].on = msgJson.on;
const change = {
name: msgJson.name,
on: msgJson.on
};
this.emit('stateChange', change);
});
}

View File

@ -20,4 +20,11 @@ setInterval(() => {
}).catch(e => console.error(e));
}
}
}, 1000);
}, 1000);
comms.on('stateChange', (change) => {
console.log(`State change detected: ${change.name}`);
gpio.togglePin(config.states[change.name].pin, change.on).then(() => {
console.log(`Pin ${config.states[change.name].pin} set to ${change.on}`);
});
});