lego11

Monitoraggio centrali elettriche

Apr 17th, 2026 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. -- Copyright Lego11 2026
  2. -- Programma monitoraggio centrali
  3.  
  4. cardReader1 = peripheral.wrap("left")
  5. cardReader2 = peripheral.wrap("right")
  6. while true do
  7.     time = http.get("http://172.16.20.220/luanet/servlets/timestamp.php").readAll()
  8.     print("Inizio lettura: " .. time)
  9. for i=1,9 do
  10.     a,b,c,d = cardReader1.get(i)
  11.     if (type(b) == "string" and b == "OK") then
  12.         name, fuel, power = string.match(c, "(.*),(.*),(.*)")
  13.         if (type(name) == "string" and type(fuel) == "string" and type(power) == "string") then
  14.             reading = tostring(textutils.serialize(d.average))
  15.             print("Scheda [S" .. i .. "]: " .. name .. " - " .. fuel .. " - " .. power .. " kW - " .. reading .. " kW")
  16.             restURI = string.gsub("http://172.16.20.220/luanet/servlets/ergb/centrali.php?centrale=" .. name .. "&combustibile=" .. fuel .. "&shunt=" .. reading .. "&potenza=" .. power .. "&time=" .. time, "%s", "%%20")
  17.             rest = http.get(restURI).readAll()
  18.             print(rest)
  19.         else
  20.             print("Scheda [S" .. i .. "] non valida")
  21.         end
  22.     else
  23.         print("Scheda [S" .. i .. "] non riconosciuta o non presente")
  24.     end
  25.     sleep(1)
  26. end
  27.  
  28. for i=1,9 do
  29.     a,b,c,d = cardReader2.get(i)
  30.     if (type(b) == "string" and b == "OK") then
  31.         name, fuel, power = string.match(c, "(.*),(.*),(.*)")
  32.         if (type(name) == "string" and type(fuel) == "string" and type(power) == "string") then
  33.             reading = tostring(textutils.serialize(d.average))
  34.             print("Scheda [Da" .. i .. "]: " .. name .. " - " .. fuel .. " - " .. power .. " kW - " .. reading .. " kW")
  35.             restURI = string.gsub("http://172.16.20.220/luanet/servlets/ergb/centrali.php?centrale=" .. name .. "&combustibile=" .. fuel .. "&shunt=" .. reading .. "&potenza=" .. power .. "&time=" .. time, "%s", "%%20")
  36.             rest = http.get(restURI).readAll()
  37.             print(rest)
  38.         else
  39.             print("Scheda [D" .. i .. "] non valida")
  40.         end
  41.     else
  42.         print("Scheda [D" .. i .. "] non riconosciuta o non presente")
  43.     end
  44.     sleep(1)
  45. end
  46. for i=30,1,-1 do
  47.     print("Attesa: " .. i)
  48.     sleep(1)
  49. end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment