-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flash RFID readers from admin panel (#42)
* Automatic RFID reader code reworked and refined. Also some bug fixes etc... * Fix pylint
- Loading branch information
Showing
9 changed files
with
308 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"DEBUG": false, | ||
"TESTING": false, | ||
"SECRET_KEY": "secret_key", | ||
"USE_X_SENDFILE": false, | ||
"APPLICATION_ROOT": "/", | ||
"SESSION_COOKIE_NAME": "session", | ||
"SESSION_COOKIE_HTTPONLY": true, | ||
"SESSION_COOKIE_SECURE": false, | ||
"SESSION_REFRESH_EACH_REQUEST": true, | ||
"TRAP_HTTP_EXCEPTIONS": false, | ||
"EXPLAIN_TEMPLATE_LOADING": false, | ||
"PREFERRED_URL_SCHEME": "http", | ||
"MAX_COOKIE_SIZE": 4093, | ||
"DATABASE_URI": "file:database.db", | ||
"PRISMO": { | ||
"READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/path/to/reader/firmware/src/flasher.sh", | ||
"CURRENT_CONFIG_FILE": "config_debug.json", | ||
"NOTIFIER": { | ||
"CURRENT_NOTIFIER": "SLACK", | ||
"SLACK_CHANNEL": "#prismo-debug", | ||
"SLACK_TOKEN": "xoxb-THIS-ISNOTAREAL-SLACKTOKEN" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Global: Device ID, which is pending for update | ||
let deviceIDForUpdate = null; | ||
|
||
function flashFirmware() { | ||
console.log("Flashing device: ", deviceIDForUpdate); | ||
const socket = new WebSocket("ws://" + location.host + "/reader_flasher"); | ||
const logContainer = document.getElementById("log-container"); | ||
|
||
let progress = 0; | ||
|
||
socket.addEventListener("open", () => { | ||
console.log( | ||
"WebSocket connection established, send device id for flashing", | ||
); | ||
socket.send(deviceIDForUpdate); | ||
}); | ||
function log(data) { | ||
const obj = JSON.parse(data); | ||
logContainer.innerHTML += `<span>${obj.text}</span><br>`; | ||
|
||
// Update progress bar | ||
document.querySelector(".progress-bar").style.width = `${obj.progress}%`; | ||
document.getElementById("statusText").innerText = `${obj.status}`; | ||
} | ||
|
||
function toggleLog() { | ||
logContainer.style.display = | ||
logContainer.style.display === "block" ? "none" : "block"; | ||
} | ||
|
||
socket.addEventListener("message", (ev) => { | ||
log(ev.data); | ||
}); | ||
} | ||
|
||
fetch("/api/devices") | ||
.then((response) => response.json()) | ||
.then((data) => generateAccordionItems(data)) | ||
.catch((error) => console.error("Error fetching data:", error)); | ||
|
||
function generateAccordionItems(devices) { | ||
const accordionItemsHTML = []; | ||
for (const device of devices) { | ||
const accordionItemHTML = ` | ||
<div class="accordion-item"> | ||
<h2 class="accordion-header"> | ||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapse-${device.id}" aria-expanded="false" aria-controls="flush-collapse-${device.id}"> | ||
<i class="bi bi-phone-vibrate-fill"></i> | ${device.name} | ||
</button> | ||
</h2> | ||
<div id="flush-collapse-${device.id}" class="accordion-collapse collapse" data-bs-parent="#accordionFlushExample"> | ||
<div class="accordion-body"> | ||
<div class="d-flex justify-content-between align-items-center"> | ||
<div class="me-3"> | ||
Device id: ${device.id}, Device type: ${device.type} | ||
</div> | ||
<div> | ||
<button type="button" class="btn btn-primary me-3" data-bs-toggle="modal" data-bs-target="#flashDeviceModal" onclick="deviceIDForUpdate='${device.id}'">Flash Connected Device</button> | ||
<button type="button" class="btn btn-danger" onclick="removeDevice('${device.id}')">Remove Device</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
accordionItemsHTML.push(accordionItemHTML); | ||
} | ||
const devicesListElement = document.getElementById("devicesList"); | ||
devicesListElement.innerHTML = accordionItemsHTML.join(""); | ||
} | ||
|
||
function addDevice(deviceName) { | ||
// Generate random UUID for device ID | ||
const deviceId = crypto.randomUUID(); | ||
// Prepare device data | ||
const deviceData = { | ||
device_name: deviceName, | ||
device_id: deviceId, | ||
device_type: "tool", | ||
}; | ||
// Make API call to add device | ||
fetch("/api/devices", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(deviceData), | ||
}) | ||
.then((response) => { | ||
// Check if response status code is 201 (Created) | ||
if (response.status === 201) { | ||
alert("Device added successfully!"); | ||
refreshDevicesList(); | ||
} else { | ||
alert("Error adding device. Please try again later."); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error("Error adding device:", error); | ||
alert("Error adding device. Please try again later."); | ||
}); | ||
} | ||
|
||
function removeDevice(deviceId) { | ||
fetch(`/api/devices/${deviceId}`, { | ||
method: "DELETE", | ||
}) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
alert("Device removed successfully!"); | ||
refreshDevicesList(); | ||
} else { | ||
alert("Error removing device. Please try again later."); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error("Error removing device:", error); | ||
alert("Error removing device. Please try again later."); | ||
}); | ||
} | ||
|
||
function refreshDevicesList() { | ||
fetch("/api/devices") | ||
.then((response) => response.json()) | ||
.then((data) => generateAccordionItems(data)) | ||
.catch((error) => console.error("Error fetching data:", error)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.