diff --git a/src/_EMR/mqtt.sh b/src/_EMR/mqtt.sh new file mode 100644 index 0000000..b4fc580 --- /dev/null +++ b/src/_EMR/mqtt.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Path variables +ROOT_PATH="/srv/hestia" +EMR_FOLDER="src/_EMR" +MQTT_HOST="192.168.0.12" +IGN_TOPIC="hestia/v2/igniter" +EXH_TOPIC="hestia/v2/exhaust" +AUG_TOPIC="hestia/v2/auger" +FR_TOPIC="hestia/v2/feed-rate" + +# Loop +while true; do + # Prompt for input + echo "###################################" + echo "# Hestia Emergency MQTT Panel #" + echo "###################################" + echo "# 1. Toggle Exhaust #" + echo "# 2. Toggle Igniter #" + echo "# 3. Toggle Auger Loop #" + echo "# 4. Set Feed Rate #" + echo "# 5. Edit ENV Variables #" + echo "###################################" + echo "# 0. Exit #" + echo "###################################" + + # Read user input + read -p "Menu Option: " choice + + # Switch case on input + case $choice in + 1) + echo "Toggling Exhaust" + cd $ROOT_PATH + mosquitto_pub -h $MQTT_HOST -t $EXH_TOPIC -m "toggle" + ;; + 2) + echo "Toggling Igniter" + cd $ROOT_PATH + mosquitto_pub -h $MQTT_HOST -t $IGN_TOPIC -m "toggle" + ;; + 3) + echo "Toggling Auger Loop" + cd $ROOT_PATH + mosquitto_pub -h $MQTT_HOST -t $AUG_TOPIC -m "toggle" + ;; + 4) + echo "Setting Feed Rate" + read -p "Enter Feed Rate: " feed_rate + cd $ROOT_PATH + mosquitto_pub -h $MQTT_HOST -t $FR_TOPIC -m $feed_rate + ;; + 5) + echo "Editing ENV Variables" + nano $ROOT_PATH/.env + ;; + 0) + echo "Exiting" + exit + break + ;; + *) + echo "Invalid input" + ;; + esac +done \ No newline at end of file diff --git a/src/custom_modules/HestiaClasses.js b/src/custom_modules/HestiaClasses.js index 889fdff..f815a23 100644 --- a/src/custom_modules/HestiaClasses.js +++ b/src/custom_modules/HestiaClasses.js @@ -73,6 +73,22 @@ module.exports = { topic: config.mqtt.topics.startup }; + this.v2igniter = { + topic: config.mqtt.topics.v2igniter + }; + + this.v2exhaust = { + topic: config.mqtt.topics.v2exhaust + }; + + this.v2auger = { + topic: config.mqtt.topics.v2auger + }; + + this.v2feedRate = { + topic: config.mqtt.topics.v2feedRate + }; + this.shutdown = { topic: config.mqtt.topics.shutdown }; @@ -141,7 +157,23 @@ module.exports = { // Empty block for 'hestia/command' topics this.emit('shutdown'); } else { - this.emit('announcement', `Unknown topic: ${topic}`); + switch (topic) { + case 'hestia/v2/igniter': + this.emit('igniter', message.toString()); + break; + case 'hestia/v2/exhaust': + this.emit('exhaust', message.toString()); + break; + case 'hestia/v2/auger': + this.emit('auger', message.toString()); + break; + case 'hestia/v2/feed-rate': + this.emit('feedRate', message.toString()); + break; + default: + this.emit('announcement', `Unknown topic: ${topic}`); + break; + } } }); diff --git a/src/custom_modules/config.json b/src/custom_modules/config.json index 4b69e7a..2b08279 100644 --- a/src/custom_modules/config.json +++ b/src/custom_modules/config.json @@ -7,7 +7,11 @@ "pof": "hestia/status/pof", "vacuum": "hestia/status/vacuum", "startup": "hestia/command/startup", - "shutdown": "hestia/command/shutdown" + "shutdown": "hestia/command/shutdown", + "v2igniter": "hestia/v2/igniter", + "v2exhaust": "hestia/v2/exhaust", + "v2auger": "hestia/v2/auger", + "v2feedRate": "hestia/v2/feed-rate" } }, "states": { @@ -18,7 +22,11 @@ "pof", "vacuum", "startup", - "shutdown" + "shutdown", + "v2igniter", + "v2exhaust", + "v2auger", + "v2feedRate" ] }, "pins": [ diff --git a/src/main.js b/src/main.js index 4d4db59..984fc36 100644 --- a/src/main.js +++ b/src/main.js @@ -79,6 +79,26 @@ process.psState.on('announcement', msg => { fn.log(`State: ${msg}`, 'INFO'); }); +process.comlink.on('igniter', (message) => { + fn.log(`ComLink: V2 Igniter: ${message}`, 'INFO'); + // TODO: Implement Igniter toggle +}); + +process.comlink.on('exhaust', (message) => { + fn.log(`ComLink: V2 Exhaust: ${message}`, 'INFO'); + // TODO: Implement Exhaust toggle +}); + +process.comlink.on('auger', (message) => { + fn.log(`ComLink: V2 Auger: ${message}`, 'INFO'); + // TODO: Implement Auger toggle +}); + +process.comlink.on('feed-rate', (message) => { + fn.log(`ComLink: V2 Feed Rate: ${message}`, 'INFO'); + // TODO: Implement Feed Rate toggle +}); + /***************************************************************************************/ // Call Things /***************************************************************************************/