const { Gumband, Sockets } = require('@deeplocal/gumband-node-sdk');
const EXHIBIT_ID = '40';
const EXHIBIT_TOKEN = 'a45ne3...';
const gb = new Gumband(
EXHIBIT_TOKEN,
EXHIBIT_ID,
'./manifest.json',
{
useLocalMQTTBroker: true, // Enable the hardware MQTT broker
//MQTTBrokerPort: 1883, // Port for the MQTT broker, defaults to 1883
}
);
gb.on(Sockets.READY, async () => {
console.log('Gumband Ready!');
});
// Event when hardware connects and registers
gb.on(Sockets.HARDWARE_REGISTERED, async (payload) => {
console.log(`Hardware with ID ${payload.id} registered.`);
});
// Event when hardware disconnects
gb.on(Sockets.HARDWARE_DISCONNECTED, async (payload) => {
console.log(`Hardware with ID ${payload.id} disconnected.`);
});
// Event when hardware sends a property
gb.on(Sockets.HARDWARE_PROPERTY_RECEIVED, async (payload) => {
//console.log(`Hardware ID ${payload.id} sent a property`);
//console.log(` property: "${payload.property}"`);
//console.log(` value: ${payload.value}`);
// If we receive the Button/Press property
if(payload.property === 'Button/Press') {
// If the button is pressed
if(payload.value == 1) {
console.log(`Button pressed!`);
// Set the LED/Toggle property to 1 (on)
gb.hardware.set(`${payload.id}/LED/Toggle`, 1);
}
// If the button is not pressed
else {
console.log(`Button released!`);
// Set the LED/Toggle property to 0 (off)
gb.hardware.set(`${payload.id}/LED/Toggle`, 0);
}
}
});
|