From bc40911f2f53fcaad62c569422960e6600098aae Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Apr 2018 15:33:47 +0200 Subject: [PATCH] Quit zigbee-shepherd friendly. --- index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fba2a54e4..652177b9d 100644 --- a/index.js +++ b/index.js @@ -40,6 +40,7 @@ shepherd.on('ready', handleReady); shepherd.on('permitJoining', handlePermitJoining); client.on('connect', handleConnect); shepherd.on('ind', handleInd); +process.on('SIGINT', handleQuit); // Start server console.log(`Starting zigbee-shepherd with device ${args.device}`) @@ -150,4 +151,17 @@ function handleInd(msg) { console.log("MQTT Reporting to ", topic, " value ", pl) client.publish(topic, pl.toString()); } -} \ No newline at end of file +} + +function handleQuit() { + console.log("Stopping zigbee-shepherd..."); + shepherd.stop((err) => { + if (err) { + console.error('Error while stopping zigbee-shepherd'); + } else { + console.error('zigbee-shepherd stopped') + } + + process.exit(); + }); +}