Modification du buzzer-manager

This commit is contained in:
2026-01-23 18:40:23 +01:00
parent da929ecb89
commit 0186a0a83e

View File

@@ -2,7 +2,7 @@
const mqtt = require('mqtt');
// MQTT broker configuration
const brokerUrl = 'mqtt://localhost'; // Broker URL (change if needed)
const brokerUrl = 'mqtt://192.168.1.178'; // Broker URL (change if needed)
const clientId = 'buzzer_manager';
const options = {
clientId,
@@ -64,8 +64,7 @@ function sendTiltStatus(action, buzzerId) {
client.publish('vulture/buzzer/status', JSON.stringify({
status: "tilt_update",
tilt_buzzers: tiltList,
message: `Buzzer ID ${buzzerId} ${action} to tilt mode`,
timestamp: new Date().toISOString()
message: `Buzzer ID ${buzzerId} ${action} to tilt mode`
}));
console.log(`[INFO] Tilt status updated: ${tiltList.length} buzzers in tilt mode`);
@@ -106,8 +105,7 @@ client.on('message', (topic, message) => {
status: "received",
action: status,
buzzer_id: buzzer_id,
message: `Tilt command '${status}' received for buzzer ID ${buzzer_id}`,
timestamp: new Date().toISOString()
message: `Tilt command '${status}' received for buzzer ID ${buzzer_id}`
}));
// Send the updated tilt status to all components
@@ -131,8 +129,7 @@ client.on('message', (topic, message) => {
client.publish(`vulture/buzzer/confirmation/${buzzerId}`, JSON.stringify({
status: "received",
buzzer_id: buzzerId,
message: `Buzzer ID ${buzzerId} received (Color: ${color})`,
timestamp: new Date().toISOString()
message: `Buzzer ID ${buzzerId} received (Color: ${color})`
}));
// Ignore if the buzzer is in tilt mode, but notify this event
@@ -143,8 +140,7 @@ client.on('message', (topic, message) => {
client.publish(`vulture/buzzer/tilt/ignored/${buzzerId}`, JSON.stringify({
status: "tilt_ignored",
buzzer_id: buzzerId,
message: `Buzzer ID ${buzzerId} is in tilt mode and ignored.`,
timestamp: new Date().toISOString()
message: `Buzzer ID ${buzzerId} is in tilt`
}));
return;
}
@@ -154,8 +150,7 @@ client.on('message', (topic, message) => {
buzzer_id: buzzerId,
color: color,
status: buzzerActive ? "blocked" : "free",
message: `Activity detected on buzzer ID ${buzzerId} (Color: ${color})`,
timestamp: new Date().toISOString()
message: `Activity detected on buzzer ID ${buzzerId} (Color: ${color})`
}));
if (!buzzerActive) {
@@ -176,8 +171,7 @@ client.on('message', (topic, message) => {
status: "blocked",
buzzer_id: buzzerId,
color: color,
message: `Buzzer activated by ID ${buzzerId} (Color: ${color})`,
timestamp: new Date().toISOString()
message: `Buzzer activated by ID ${buzzerId} (Color: ${color})`
}));
console.log(`[INFO] Buzzers blocked and notification sent`);
@@ -188,19 +182,12 @@ client.on('message', (topic, message) => {
if (topic === 'vulture/buzzer/unlock') {
console.log('[INFO] Buzzer unlock requested');
// Confirm receipt of unlock command
client.publish('vulture/buzzer/unlock/confirmation', JSON.stringify({
status: "received",
message: "Buzzer unlock command received.",
timestamp: new Date().toISOString()
}));
// Notify the light manager to change to the team's color
client.publish('vulture/light/change', JSON.stringify({
color: "#FFFFFF",
effect: 'rainbow'
}));
// Reset buzzer manager state
buzzerActive = false;
buzzerThatPressed = null;
@@ -208,8 +195,7 @@ client.on('message', (topic, message) => {
// Notify all components of buzzer unlock
client.publish('vulture/buzzer/status', JSON.stringify({
status: "unblocked",
message: "Buzzers unblocked and ready for activation.",
timestamp: new Date().toISOString()
message: "Buzzers unblocked and ready for activation."
}));
console.log('[INFO] Buzzers unblocked and notification sent');