scene and function
This commit is contained in:
119
main.lua
119
main.lua
@@ -4,5 +4,122 @@
|
||||
--
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
-- Your code here
|
||||
-- Importiere das ASKI Repository
|
||||
local AskiRepository = require("askirepository")
|
||||
local json = require("json")
|
||||
local composer = require("composer")
|
||||
|
||||
-- Konfiguration Authentifizierungsfunktion
|
||||
local postAuthUrl = "https://api.portal.aski.at/auth/login"
|
||||
local email = "David.aschl@ifn-holding.com"
|
||||
local password = "20IFN25"
|
||||
local code = ""
|
||||
local cookie = nil
|
||||
|
||||
-- Konfiguration für den Abruf von Daten mit Cookie-Authentifizierungsfunktion
|
||||
local fromDate = "2026-05-07T00:00:00.000Z"
|
||||
local toDate = "2026-05-07T23:59:59.999Z"
|
||||
local postDataUrl = "https://api.portal.aski.at/historical_values/power"
|
||||
local devices = {
|
||||
{
|
||||
deviceId = "08dd1489-1129-4774-81ed-9bf1ce3f580d",
|
||||
name = "Traun"
|
||||
},
|
||||
{
|
||||
deviceId = "08dd20cd-9d7f-4a2e-897a-3be55c3bfec3",
|
||||
name = "Lannach"
|
||||
},
|
||||
{
|
||||
deviceId = "08dd0ac5-7510-4990-8124-39cf64ec7e71",
|
||||
name = "Sarleinsbach"
|
||||
}
|
||||
}
|
||||
|
||||
local deviceDataSets = {}
|
||||
local completedRequests = 0
|
||||
local totalRequests = 0
|
||||
|
||||
-- Einfache Lade-Anzeige
|
||||
local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight)
|
||||
background:setFillColor(0.95, 0.95, 0.95)
|
||||
|
||||
local loadingText = display.newText({
|
||||
text = "Verbinde mit Server...",
|
||||
x = display.contentCenterX,
|
||||
y = display.contentCenterY,
|
||||
fontSize = 24,
|
||||
font = native.systemFont
|
||||
})
|
||||
loadingText:setFillColor(0.3, 0.3, 0.8)
|
||||
|
||||
-- Callback-Funktion für den Datenabruf (wird für jedes Device aufgerufen)
|
||||
local function onDataComplete(deviceName, success, dataSet, response)
|
||||
completedRequests = completedRequests + 1
|
||||
|
||||
if success then
|
||||
print("✓ Datenabruf für " .. deviceName .. " erfolgreich!")
|
||||
deviceDataSets[deviceName] = dataSet
|
||||
else
|
||||
print("✗ Datenabruf für " .. deviceName .. " fehlgeschlagen: " .. tostring(response))
|
||||
deviceDataSets[deviceName] = { error = tostring(response) }
|
||||
end
|
||||
|
||||
-- Aktualisiere Status
|
||||
loadingText.text = string.format("Lade Daten... (%d/%d)", completedRequests, totalRequests)
|
||||
|
||||
-- Wenn alle Requests abgeschlossen sind, wechsle zur Scene
|
||||
if completedRequests >= totalRequests then
|
||||
print("✓ Alle DataSets geladen - Wechsle zur Scene01")
|
||||
|
||||
-- Entferne Lade-Anzeige
|
||||
loadingText:removeSelf()
|
||||
background:removeSelf()
|
||||
|
||||
-- Wechsle zur Datenansicht-Scene und übergebe die Daten
|
||||
composer.gotoScene("scenen.scene01", {
|
||||
effect = "fade",
|
||||
time = 500,
|
||||
params = {
|
||||
deviceDataSets = deviceDataSets,
|
||||
devices = devices
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback-Funktion für die Authentifizierung
|
||||
local function onAuthComplete(success, receivedCookie, response)
|
||||
if success then
|
||||
print("✓ Authentifizierung erfolgreich!")
|
||||
print("✓ Cookie erhalten und kann verwendet werden")
|
||||
|
||||
loadingText.text = "Authentifiziert - Lade Daten..."
|
||||
|
||||
-- Hier kannst du mit dem Cookie weiterarbeiten
|
||||
cookie = receivedCookie
|
||||
print("✓ Cookie: " .. cookie)
|
||||
|
||||
-- Setze die Anzahl der erwarteten Requests
|
||||
totalRequests = #devices
|
||||
completedRequests = 0
|
||||
|
||||
-- Rufe die Datenabruf-Funktion für alle Devices auf
|
||||
for i, device in ipairs(devices) do
|
||||
print("Lade Daten für " .. device.name .. " (" .. device.deviceId .. ")")
|
||||
|
||||
-- Erstelle einen spezifischen Callback für dieses Device
|
||||
local function deviceCallback(success, dataSet, response)
|
||||
onDataComplete(device.name, success, dataSet, response)
|
||||
end
|
||||
|
||||
AskiRepository.getPostHistoricData(postDataUrl, device.deviceId, fromDate, toDate, cookie, deviceCallback)
|
||||
end
|
||||
else
|
||||
print("✗ Authentifizierung fehlgeschlagen: " .. tostring(response))
|
||||
loadingText.text = "✗ Authentifizierung fehlgeschlagen"
|
||||
loadingText:setFillColor(0.8, 0.2, 0.2)
|
||||
end
|
||||
end
|
||||
|
||||
-- Rufe die Authentifizierungsfunktion auf
|
||||
AskiRepository.getPostCookieAuth(postAuthUrl, email, password, code, onAuthComplete)
|
||||
Reference in New Issue
Block a user