1
0
forked from jchomaz/Vulture

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