From dacdde992417da79a1503a44fe7e9a9f4004d80d Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Fri, 4 Oct 2024 18:57:38 +0200 Subject: [PATCH] fixes --- ledder/animations/MQTT.ts | 20 ++++++++++++++++++-- presets/MQTT/default.json | 16 ---------------- presets/MQTT/{localhost.json => hsd.json} | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 presets/MQTT/default.json rename presets/MQTT/{localhost.json => hsd.json} (94%) diff --git a/ledder/animations/MQTT.ts b/ledder/animations/MQTT.ts index cf19eb47..70368b13 100644 --- a/ledder/animations/MQTT.ts +++ b/ledder/animations/MQTT.ts @@ -45,7 +45,7 @@ export default class MQTT extends Animator { this.box = box - const mqttHost = controls.input('MQTT host', "mqtt", true) + const mqttHost = controls.input('MQTT host', "localhost", true) const mqttTopic = controls.input('MQTT topic', "ledder", true) let childControls = controls.group('Current animation') @@ -54,10 +54,26 @@ export default class MQTT extends Animator { this.animationManager = new AnimationManager(box, scheduler.child(), childControls) - this.statusMessage(`Conn ${mqttHost.text}...`) + this.statusMessage(`conn ${mqttHost.text}`) console.log(`MQTT: Connecting ${mqttHost.text}`) let mqttClient = mqtt.connect("mqtt://" + mqttHost.text, {}) + mqttClient.on('connect', ()=>{ + console.log(`MQTT: ${mqttHost.text} connected`) + this.statusMessage("conn ok") + }) + + mqttClient.on('disconnect', ()=>{ + console.log(`MQTT: ${mqttHost.text} disconnected`) + this.statusMessage("disc.") + }) + + mqttClient.on('error', (e)=>{ + console.log(`MQTT: ${mqttHost.text} error ${e}`) + this.statusMessage("error") + }) + + //recursively send all control values to mqtt function sendControls(topic: string, controlGroup: ControlGroup) { diff --git a/presets/MQTT/default.json b/presets/MQTT/default.json deleted file mode 100644 index e8927943..00000000 --- a/presets/MQTT/default.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "title": "", - "description": "", - "values": { - "FPS": { - "value": 60 - }, - "MQTT host": { - "text": "192.168.1.10" - }, - "MQTT topic": { - "text": "ledder" - }, - "Current animation": {} - } -} \ No newline at end of file diff --git a/presets/MQTT/localhost.json b/presets/MQTT/hsd.json similarity index 94% rename from presets/MQTT/localhost.json rename to presets/MQTT/hsd.json index d2c0e129..6e60007c 100644 --- a/presets/MQTT/localhost.json +++ b/presets/MQTT/hsd.json @@ -6,7 +6,7 @@ "value": 60 }, "MQTT host": { - "text": "localhost" + "text": "mqtt.hackerspace-drenthe.nl" }, "MQTT topic": { "text": "ledder"