MQTT v2 Testing

This commit is contained in:
Skylar Grant 2024-12-01 17:38:51 -05:00
parent a92a71d5e7
commit 894c6a68fd
4 changed files with 129 additions and 3 deletions

66
src/_EMR/mqtt.sh Normal file
View File

@ -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

View File

@ -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 {
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;
}
}
});

View File

@ -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": [

View File

@ -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
/***************************************************************************************/