changed direct backend access
This commit is contained in:
@@ -66,6 +66,8 @@
|
|||||||
// Globale Variablen
|
// Globale Variablen
|
||||||
let rfidData = [];
|
let rfidData = [];
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
let DBUrl = "db.reptilfpv.de:3000";
|
||||||
|
var APIKey;
|
||||||
|
|
||||||
// Maximales Datum auf heute setzen
|
// Maximales Datum auf heute setzen
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
@@ -244,6 +246,7 @@
|
|||||||
window.addEventListener('load', function() {
|
window.addEventListener('load', function() {
|
||||||
document.getElementById('uid').focus();
|
document.getElementById('uid').focus();
|
||||||
checkServerStatus();
|
checkServerStatus();
|
||||||
|
loadLicence();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enter-Taste in UID Feld zum nächsten Feld springen
|
// Enter-Taste in UID Feld zum nächsten Feld springen
|
||||||
@@ -348,6 +351,18 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadLicence() {
|
||||||
|
fetch("/api/get-licence")
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
APIKey = data.licence || "";
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch((error) =>
|
||||||
|
showMessage("Fehler beim Laden der Lizenz", "error")
|
||||||
|
);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -264,14 +264,13 @@
|
|||||||
|
|
||||||
// Einstellungen laden beim Seitenaufruf
|
// Einstellungen laden beim Seitenaufruf
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
|
loadLicence();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
loadWifiSettings();
|
loadWifiSettings();
|
||||||
loadSystemInfo();
|
loadSystemInfo();
|
||||||
loadCurrentTime();
|
loadCurrentTime();
|
||||||
updateCurrentTimeDisplay();
|
updateCurrentTimeDisplay();
|
||||||
loadLicence();
|
|
||||||
loadWifiSettings();
|
loadWifiSettings();
|
||||||
loadLocations();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Aktuelle Zeit anzeigen (Live-Update)
|
// Aktuelle Zeit anzeigen (Live-Update)
|
||||||
@@ -460,7 +459,7 @@
|
|||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
document.getElementById("licencekey").value = data.licence || "";
|
document.getElementById("licencekey").value = data.licence || "";
|
||||||
|
loadLocations();
|
||||||
})
|
})
|
||||||
.catch((error) =>
|
.catch((error) =>
|
||||||
showMessage("Fehler beim Laden der Lizenz", "error")
|
showMessage("Fehler beim Laden der Lizenz", "error")
|
||||||
@@ -790,33 +789,41 @@
|
|||||||
//location functions
|
//location functions
|
||||||
// Locations laden und Dropdown befüllen
|
// Locations laden und Dropdown befüllen
|
||||||
function loadLocations() {
|
function loadLocations() {
|
||||||
fetch("/api/location/")
|
const licence = document.getElementById("licencekey").value; // Get the licence key from the input field
|
||||||
.then((response) => response.json())
|
fetch("http://db.reptilfpv.de:3000/api/location/", {
|
||||||
.then((data) => {
|
method: "GET",
|
||||||
const select = document.getElementById("locationSelect");
|
headers: {
|
||||||
|
Authorization: `Bearer ${licence}`, // Add Bearer token using licenkey
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
|
||||||
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
|
const select = document.getElementById("locationSelect");
|
||||||
while (select.children.length > 1) {
|
|
||||||
select.removeChild(select.lastChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Neue Optionen aus Backend-Response hinzufügen
|
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
|
||||||
data.forEach((location) => {
|
while (select.children.length > 1) {
|
||||||
const option = document.createElement("option");
|
select.removeChild(select.lastChild);
|
||||||
option.value = location.id;
|
|
||||||
option.textContent = location.name;
|
|
||||||
select.appendChild(option);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Aktuell gespeicherten Standort laden
|
|
||||||
loadCurrentLocation();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("Locations konnten nicht geladen werden:", error);
|
|
||||||
showMessage("Fehler beim Laden der Standorte", "error");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Neue Optionen aus Backend-Response hinzufügen
|
||||||
|
// Neue Optionen aus Backend-Response hinzufügen
|
||||||
|
data.forEach((location) => {
|
||||||
|
const option = document.createElement("option");
|
||||||
|
option.value = location.id;
|
||||||
|
option.textContent = location.name;
|
||||||
|
select.appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Aktuell gespeicherten Standort laden
|
||||||
|
loadCurrentLocation();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("Locations konnten nicht geladen werden:", error);
|
||||||
|
showMessage("Fehler beim Laden der Locations", "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Aktuell gespeicherten Standort laden
|
// Aktuell gespeicherten Standort laden
|
||||||
function loadCurrentLocation() {
|
function loadCurrentLocation() {
|
||||||
fetch("/api/get-location")
|
fetch("/api/get-location")
|
||||||
|
|||||||
@@ -5,9 +5,13 @@
|
|||||||
|
|
||||||
|
|
||||||
const char* BACKEND_SERVER = "http://db.reptilfpv.de:3000";
|
const char* BACKEND_SERVER = "http://db.reptilfpv.de:3000";
|
||||||
const char* BACKEND_TOKEN = "a4514dc0-15f5-4299-8826-fffb3139d39c";
|
String BACKEND_TOKEN = licence; // Use the licence as the token for authentication
|
||||||
|
|
||||||
|
|
||||||
bool backendOnline() {
|
bool backendOnline() {
|
||||||
|
|
||||||
|
Serial.println(licence);
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.println("No WiFi connection.");
|
Serial.println("No WiFi connection.");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ void setup() {
|
|||||||
loadBestTimes();
|
loadBestTimes();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
loadWifiSettings();
|
loadWifiSettings();
|
||||||
|
loadLocationSettings();
|
||||||
|
|
||||||
setupWifi(); // WiFi initialisieren
|
setupWifi(); // WiFi initialisieren
|
||||||
setupOTA(&server);
|
setupOTA(&server);
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ server.on("/api/set-location", HTTP_POST, [](AsyncWebServerRequest *request) {
|
|||||||
|
|
||||||
server.on("/api/get-location", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/api/get-location", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
DynamicJsonDocument doc(128);
|
DynamicJsonDocument doc(128);
|
||||||
|
loadLocationSettings();
|
||||||
doc["locationid"] = masterlocation ? masterlocation : "";
|
doc["locationid"] = masterlocation ? masterlocation : "";
|
||||||
String result;
|
String result;
|
||||||
serializeJson(doc, result);
|
serializeJson(doc, result);
|
||||||
|
|||||||
Reference in New Issue
Block a user