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',
{
gbttEnabled: true, // Enable the hardware MQTT broker
//gbttPort: 1883, // Port for the MQTT broker, defaults to 1883
//noInternetConnection: true, // SDK in offline mode
//noInternetHardwareIds: [] // Array of offline hardware IDs
}
);
gb.on(Sockets.READY, async () => {
console.log('Gumband Ready!');
});
// Event when hardware comes online/connects
gb.on(Sockets.HARDWARE_ONLINE, async (payload) => {
console.log(`Hardware with ID ${payload.hardwareId} connected.`);
});
// Event when hardware comes offline/disconnects
gb.on(Sockets.HARDWARE_OFFLINE, async (payload) => {
console.log(`Hardware with ID ${payload.hardwareId} disconnected.`);
});
// Event when hardware sends a property
gb.on(Sockets.HARDWARE_PROPERTY_RECEIVED, async (payload) => {
//console.log(`Hardware ID ${payload.hardwareId} sent a property`);
//console.log(` property: "${payload.peripheral}/${payload.property}"`);
//console.log(` value: ${payload.value}`);
// If we receive the Button/Press property
if(payload.peripheral === 'Button' && payload.property === '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.hardwareId}/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.hardwareId}/LED/Toggle`, 0);
}
}
});
|