From 7effbdb27a6df7475edbf2e6bb8bb4d67a0c715e Mon Sep 17 00:00:00 2001 From: Mike Vostrikov <11011125+mikevostrikov@users.noreply.github.com> Date: Sat, 19 Aug 2023 01:48:23 -0400 Subject: [PATCH 1/3] Force process crash on mqtt error To circumvent this error https://community.flic.io/topic/18257/cannot-push-beyond-allocated-stack-fatal-error --- main.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 33c6823..ee8faad 100644 --- a/main.js +++ b/main.js @@ -218,12 +218,10 @@ mqtt.on('disconnected', function() { mqtt.connect(); }); -mqtt.on('error', function() { - setTimeout(function (){ - mqtt.connect(); - }, 1000); +mqtt.on('error', function () { + setTimeout(function () { + throw new Error("Crashed") + }, 1000); }); - - mqtt.connect(); From 65445562020a0935e16a3980324ed39e59f59f21 Mon Sep 17 00:00:00 2001 From: Mike Vostrikov <11011125+mikevostrikov@users.noreply.github.com> Date: Sat, 19 Aug 2023 01:49:31 -0400 Subject: [PATCH 2/3] Add key mqtt events logging --- main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.js b/main.js index ee8faad..bb0033e 100644 --- a/main.js +++ b/main.js @@ -210,15 +210,18 @@ function register_allbuttons(){ //This runs on startup, it performs the actual "discovery" announcement for //HomeAssistant to add the device to its inventory mqtt.on('connected', function(){ + console.log("\n'Connected' event\n"); register_allbuttons(); }); // Added by heroash88 to reconnect if MQTT server goes down mqtt.on('disconnected', function() { + console.log("\n'Disconnected' event\n"); mqtt.connect(); }); mqtt.on('error', function () { + console.log("\n'Error' event\n"); setTimeout(function () { throw new Error("Crashed") }, 1000); From e18ae18bf39325a6fa5793dbebf2051579d447d6 Mon Sep 17 00:00:00 2001 From: Mike Vostrikov <11011125+mikevostrikov@users.noreply.github.com> Date: Sat, 19 Aug 2023 01:50:38 -0400 Subject: [PATCH 3/3] Remove device name prefix from sensor names --- main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index bb0033e..28912a7 100644 --- a/main.js +++ b/main.js @@ -156,7 +156,7 @@ function register_button(button) { }; //Setup config and destination for button press - obj.name = button.name + " Button Action"; + obj.name = "Button Action"; obj.state_topic = buttontopic + "/action"; obj.unique_id = "Flic_" + button.serialNumber + "_action"; @@ -167,7 +167,7 @@ function register_button(button) { }); // Setup config and destination for button state - obj.name = button.name + " Button State"; + obj.name = "Button State"; obj.state_topic = buttontopic + "/state"; obj.unique_id = "Flic_" + button.serialNumber + "_state"; @@ -178,7 +178,7 @@ function register_button(button) { }); //Setup config and destination for battery level report - obj.name = button.name + " Battery Level"; + obj.name = "Battery Level"; obj.state_topic = buttontopic + "/battery"; obj.unique_id = "Flic_" + button.serialNumber + "_battery"; obj.device_class = "battery";