lego11

Lettura automatica bollette/contatori

Apr 17th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. function getCard()
  2.     print("Aspirazione carta")
  3.     rs.setOutput("left", true)
  4.     sleep(0.5)
  5.     rs.setOutput("left", false)
  6.     sleep(1)
  7. end
  8.  
  9. function unloadCard()
  10.     print("Scaricamento carta")
  11.     rs.setOutput("back", true)
  12.     sleep(0.5)
  13.     rs.setOutput("back", false)
  14.     sleep(1)
  15. end
  16.  
  17. function oustCard()
  18.     print("Carta scartata")
  19.     rs.setOutput("right", true)
  20.     sleep(0.5)
  21.     rs.setOutput("right", false)
  22.     sleep(1)
  23. end
  24.  
  25. function reloadCards()
  26.     print("Ricarico carte")
  27.     rs.setOutput("bottom", true)
  28.     for i=60,1,-1 do
  29.         print("Attesa: " .. i)
  30.         sleep(1)
  31.     end
  32.     rs.setOutput("bottom", false)
  33. end
  34.  
  35.  
  36. sensor = peripheral.wrap("top")
  37. print("Avviato")
  38. while true do
  39.     getCard()
  40.     print("Lettura carta")
  41.     a,b,c,d = sensor.get(1)
  42.     if (type(b) == "string" and b == "OK") then
  43.         name, contract, id = string.match(c, "(.*),(.*),(.*)")
  44.         if (type(name) == "string" and type(contract) == "string" and type(id) == "string") then
  45.             print("Nome: ".. name)
  46.             print("Contratto: " .. contract .. " kW")
  47.             print(b)
  48.             print("Consumo: " .. tostring(textutils.serialize(d.energy)) .. "Wh")
  49.             print("Contatore: " .. id .. " ")
  50.             print("...................")
  51.             rest = http.get("http://luanet.rgbcraft.com/servlets/ergb/aggregatore.php?utente=" .. name .. "&contatore=" .. contract .. "," .. id .. "&lettura=" ..d.energy).readAll()
  52.             print(rest)
  53.             unloadCard()
  54.         else
  55.             oustCard()
  56.         end
  57.     else
  58.         print("val b era uguale a ")
  59.         print(b)
  60.         oustCard()
  61.     end
  62.     if (rs.getInput("front") == true) then
  63.         reloadCards()
  64.     end
  65.     sleep(2)
  66. end
Add Comment
Please, Sign In to add comment