add error catching to unlockDoor method, add event handler to delay open button
parent
06bef4ad75
commit
42952d70c4
10
script.js
10
script.js
|
|
@ -23,9 +23,9 @@
|
||||||
// make fetch function that calls cgi script with attributes (device id, api key, delay)
|
// make fetch function that calls cgi script with attributes (device id, api key, delay)
|
||||||
const unlockDoor = (e, dID, aK, d) => {
|
const unlockDoor = (e, dID, aK, d) => {
|
||||||
fetch(`${unlockUrl}?deviceID=${dID}&apiKey=${aK}&delay=${d}`)
|
fetch(`${unlockUrl}?deviceID=${dID}&apiKey=${aK}&delay=${d}`)
|
||||||
// fetch(unlockUrl)
|
.then(response => response.json())
|
||||||
.then(response => response.text())
|
.then(data => messageContainer.innerHTML = data.message)
|
||||||
.then(data => messageContainer.innerHTML = data);
|
.catch(error => messageContainer.innerHTML = `Error: ${error}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const setSettings = () => {
|
const setSettings = () => {
|
||||||
|
|
@ -75,9 +75,7 @@
|
||||||
|
|
||||||
unlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, 0));
|
unlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, 0));
|
||||||
|
|
||||||
delayUnlockButton.addEventListener("click", function () {
|
delayUnlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, delay));
|
||||||
messageContainer.innerHTML = "Delay Unlock";
|
|
||||||
});
|
|
||||||
|
|
||||||
document.body.onload = setSettings;
|
document.body.onload = setSettings;
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue