From aeb9cf6947c741c76f6773db56231b598d11ea5b Mon Sep 17 00:00:00 2001
From: James Arcus <jimbo@ucc.asn.au>
Date: Thu, 26 Sep 2024 22:58:58 +0800
Subject: [PATCH] Add better event logging

---
 main.js | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/main.js b/main.js
index fc2bf3e..eef21a7 100644
--- a/main.js
+++ b/main.js
@@ -23,9 +23,8 @@ const options = {
 const client  = mqtt.connect(`mqtt://${mqtt_host}:${mqtt_port}`, options);
 
 client.on('connect', () => {
-  console.log('Connected!');
-  // Subscribe to a topic
-  client.subscribe('door/ucc-door/+', () => {});
+  console.log(`Connected to MQTT broker ${mqtt_host}!`);
+  client.subscribe('door/#', () => {});
 });
 
 let doorState = null;
@@ -33,6 +32,8 @@ let doorOpener = null;
 
 // Receive messages
 client.on('message', (topic, message) => {
+  console.log(`Received message on topic ${topic}`);
+
   if (topic === 'door/ucc-door/state') {
     switch (message.toString()) {
       case "ON":
@@ -121,7 +122,7 @@ const server = http.createServer((req, res) => {
 
 // Run the server
 server.listen(web_port, web_host, () => {
-  console.log(`Server started on http://${web_host}:${web_port}`);
+  console.log(`HTTP server started on http://${web_host}:${web_port}`);
 });
 
 // vim: set ts=2 sts=2 sw=2 et:
-- 
GitLab