v2 MQTT Ready to test
This commit is contained in:
parent
894c6a68fd
commit
42374d094d
46
src/main.js
46
src/main.js
@ -81,22 +81,58 @@ process.psState.on('announcement', msg => {
|
||||
|
||||
process.comlink.on('igniter', (message) => {
|
||||
fn.log(`ComLink: V2 Igniter: ${message}`, 'INFO');
|
||||
// TODO: Implement Igniter toggle
|
||||
// Toggle the state
|
||||
process.psState.igniter.on = !process.psState.igniter.on;
|
||||
// Run the corresponding action
|
||||
if (process.psState.igniter.on) {
|
||||
fn.power.igniter.on().then(res => fn.log(res, 'DEBUG'))
|
||||
.catch(error => fn.log(`ComLink: Igniter: ${error}`, 'ERROR'));
|
||||
} else {
|
||||
fn.power.igniter.off().then(res => fn.log(res, 'DEBUG'))
|
||||
.catch(error => fn.log(`ComLink: Igniter: ${error}`, 'ERROR'));
|
||||
}
|
||||
});
|
||||
|
||||
process.comlink.on('exhaust', (message) => {
|
||||
fn.log(`ComLink: V2 Exhaust: ${message}`, 'INFO');
|
||||
// TODO: Implement Exhaust toggle
|
||||
// Toggle the state
|
||||
process.psState.exhaust.on = !process.psState.exhaust.on;
|
||||
// Run the corresponding action
|
||||
if (process.psState.exhaust.on) {
|
||||
fn.power.exhaust.on().then(res => fn.log(res, 'DEBUG'))
|
||||
.catch(error => fn.log(`ComLink: Exhaust: ${error}`, 'ERROR'));
|
||||
} else {
|
||||
fn.power.exhaust.off().then(res => fn.log(res, 'DEBUG'))
|
||||
.catch(error => fn.log(`ComLink: Exhaust: ${error}`, 'ERROR'));
|
||||
}
|
||||
});
|
||||
|
||||
process.comlink.on('auger', (message) => {
|
||||
fn.log(`ComLink: V2 Auger: ${message}`, 'INFO');
|
||||
// TODO: Implement Auger toggle
|
||||
// Toggle the state
|
||||
process.psState.auger.on = !process.psState.auger.on;
|
||||
// Nothing else to do since the auger loop always runs and checks the state
|
||||
fn.log(`ComLink: Auger: ${process.psState.auger.on}`, 'INFO');
|
||||
});
|
||||
|
||||
process.comlink.on('feed-rate', (message) => {
|
||||
process.comlink.on('feedRate', (message) => {
|
||||
fn.log(`ComLink: V2 Feed Rate: ${message}`, 'INFO');
|
||||
// TODO: Implement Feed Rate toggle
|
||||
// Check if the message is a number hiding in a string
|
||||
if (!isNaN(message)) {
|
||||
// Convert the message to a number
|
||||
const feedRate = parseInt(message);
|
||||
// Check if the feed rate is within the acceptable range
|
||||
if (feedRate >= 350 && feedRate <= 1000) {
|
||||
// Update the feed rate
|
||||
process.psState.auger.feedRate = feedRate;
|
||||
// Send the feed rate to the MQTT broker
|
||||
fn.log(`ComLink: Feed Rate: ${feedRate}`, 'INFO');
|
||||
} else {
|
||||
fn.log(`ComLink: Invalid Feed Rate: ${message}`, 'ERROR');
|
||||
}
|
||||
} else {
|
||||
fn.log(`ComLink: Invalid Feed Rate: ${message}`, 'ERROR');
|
||||
}
|
||||
});
|
||||
|
||||
/***************************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user