Update index.html
Browse files- index.html +36 -17
index.html
CHANGED
@@ -714,26 +714,45 @@
|
|
714 |
updateLiveChart(temp, new Date().toLocaleTimeString());
|
715 |
|
716 |
// 🔥 Webhook Integration with 30-second cooldown
|
|
|
717 |
const now = Date.now();
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
730 |
})
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
}
|
736 |
-
}
|
737 |
|
738 |
|
739 |
// Update gauge display
|
|
|
714 |
updateLiveChart(temp, new Date().toLocaleTimeString());
|
715 |
|
716 |
// 🔥 Webhook Integration with 30-second cooldown
|
717 |
+
// Webhook Integration with cooldown and retry
|
718 |
const now = Date.now();
|
719 |
+
const criticalThreshold = 50; // Could be loaded from settings
|
720 |
+
const webhookCooldown = 30000; // 30 seconds
|
721 |
+
|
722 |
+
if (temp > criticalThreshold && now - lastWebhookTimestamp > webhookCooldown) {
|
723 |
+
lastWebhookTimestamp = now;
|
724 |
+
|
725 |
+
const sendWebhook = (attempt = 1) => {
|
726 |
+
fetch('https://n8n-1r4e.onrender.com/webhook/c9e82b5a-2f26-425e-ba7d-f2c8b7d28f89', {
|
727 |
+
method: 'POST',
|
728 |
+
headers: { 'Content-Type': 'application/json' },
|
729 |
+
body: JSON.stringify({
|
730 |
+
temperature: temp,
|
731 |
+
timestamp: new Date().toISOString(),
|
732 |
+
status: getStatus(temp),
|
733 |
+
message: `⚠️ Critical temperature (${temp}°C) detected. Immediate action required.`,
|
734 |
+
deviceInfo: navigator.userAgent,
|
735 |
+
// Add any other relevant data
|
736 |
+
})
|
737 |
+
})
|
738 |
+
.then(async res => {
|
739 |
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
740 |
+
const data = await res.text();
|
741 |
+
logDebug(`Webhook successful: ${data}`);
|
742 |
+
showAlert('Critical temperature alert sent', 'success');
|
743 |
})
|
744 |
+
.catch(err => {
|
745 |
+
logDebug(`Webhook attempt ${attempt} failed: ${err.message}`);
|
746 |
+
if (attempt < 3) {
|
747 |
+
setTimeout(() => sendWebhook(attempt + 1), 5000 * attempt);
|
748 |
+
} else {
|
749 |
+
showAlert('Failed to send critical alert', 'error');
|
750 |
+
}
|
751 |
+
});
|
752 |
+
};
|
753 |
+
|
754 |
+
sendWebhook();
|
755 |
}
|
|
|
756 |
|
757 |
|
758 |
// Update gauge display
|