diff --git a/ledder/animations/MQTT.ts b/ledder/animations/MQTT.ts index 70368b1..39ffdbe 100644 --- a/ledder/animations/MQTT.ts +++ b/ledder/animations/MQTT.ts @@ -61,15 +61,16 @@ export default class MQTT extends Animator { mqttClient.on('connect', ()=>{ console.log(`MQTT: ${mqttHost.text} connected`) this.statusMessage("conn ok") + mqttClient.subscribe(mqttTopic.text+"/#") }) mqttClient.on('disconnect', ()=>{ - console.log(`MQTT: ${mqttHost.text} disconnected`) + console.error(`MQTT: ${mqttHost.text} disconnected`) this.statusMessage("disc.") }) mqttClient.on('error', (e)=>{ - console.log(`MQTT: ${mqttHost.text} error ${e}`) + console.error(`MQTT: ${mqttHost.text} error ${e}`) this.statusMessage("error") }) @@ -91,7 +92,7 @@ export default class MQTT extends Animator { mqttClient.on('message', async (topic, messageBuf) => { let message = messageBuf.toString() - // console.log(`MQTT ${topic}: ${message}`) + console.log(`MQTT ${topic}: ${message}`) this.statusMessage("") let subTopic = topic.substring(mqttTopic.text.length + 1) @@ -104,7 +105,9 @@ export default class MQTT extends Animator { console.log(`MQTT select ${message}`) await this.animationManager.select(message, false).catch((e) => { + this.animationManager.stop(false) this.statusMessage((e.message)) + console.error(e.message) }) diff --git a/ledder/server/AnimationManager.ts b/ledder/server/AnimationManager.ts index 101e4b6..c14a8b1 100644 --- a/ledder/server/AnimationManager.ts +++ b/ledder/server/AnimationManager.ts @@ -145,8 +145,16 @@ export default class AnimationManager { //select an animation and preset, load it and start it public async select(animationAndPresetPath: string, keepControls: boolean) { - this.animationName = animationAndPresetPath.match(RegExp("(^.*)/"))[1] - this.presetName = animationAndPresetPath.match(RegExp("[^/]+$"))[0] + + try { + this.animationName = animationAndPresetPath.match(RegExp("(^.*)/"))[1] + this.presetName = animationAndPresetPath.match(RegExp("[^/]+$"))[0] + } + catch (e) + { + console.error(`Invalid name: ${animationAndPresetPath}`) + return + } await this.reload(keepControls)