SHOW:
|
|
- or go back to the newest paste.
| 1 | function getCard() | |
| 2 | - | bills = "" |
| 2 | + | print("Aspirazione carta")
|
| 3 | rs.setOutput("left", true)
| |
| 4 | - | os.pullEvent("redstone")
|
| 4 | + | sleep(0.5) |
| 5 | rs.setOutput("left", false)
| |
| 6 | - | while rs.getInput("back") do
|
| 6 | + | sleep(1) |
| 7 | - | a,b,c,d = sensor.get(1) |
| 7 | + | |
| 8 | ||
| 9 | - | if (b == "OK") then |
| 9 | + | function unloadCard() |
| 10 | - | name, contract = string.match(c, "(.*),(.*)") |
| 10 | + | print("Scaricamento carta")
|
| 11 | - | print("Nome: ".. name)
|
| 11 | + | rs.setOutput("back", true)
|
| 12 | - | print("Contratto: " .. contract .. " kW")
|
| 12 | + | sleep(0.5) |
| 13 | - | print(b) |
| 13 | + | rs.setOutput("back", false)
|
| 14 | - | print("Consumo: " .. tostring(textutils.serialize(d.energy)) .. "Wh")
|
| 14 | + | sleep(1) |
| 15 | - | print("...................")
|
| 15 | + | |
| 16 | - | if(bills == "") then |
| 16 | + | |
| 17 | - | bills = bills .. tostring(name) .. "-" .. tostring(textutils.serialize(d.energy)) .. "-" .. tostring(contract) |
| 17 | + | function oustCard() |
| 18 | - | else |
| 18 | + | print("Carta scartata")
|
| 19 | - | bills = bills .. "-" .. tostring(name) .. "-" .. tostring(textutils.serialize(d.energy)) .. "-" .. tostring(contract) |
| 19 | + | rs.setOutput("right", true)
|
| 20 | - | end |
| 20 | + | sleep(0.5) |
| 21 | - | redstone.setOutput("left", true)
|
| 21 | + | rs.setOutput("right", false)
|
| 22 | - | sleep(0.5) |
| 22 | + | sleep(1) |
| 23 | - | redstone.setOutput("left", false)
|
| 23 | + | |
| 24 | - | else |
| 24 | + | |
| 25 | - | redstone.setOutput("right", true)
|
| 25 | + | function reloadCards() |
| 26 | - | sleep(0.5) |
| 26 | + | print("Ricarico carte")
|
| 27 | - | redstone.setOutput("right", false)
|
| 27 | + | rs.setOutput("bottom", true)
|
| 28 | - | end |
| 28 | + | for i=120,1,-1 do |
| 29 | - | os.sleep(1) |
| 29 | + | print("Attesa: " .. i)
|
| 30 | sleep(1) | |
| 31 | - | addBills = http.get("http://192.168.13.103/rg-energy/addBill.php?bill=" .. bills)
|
| 31 | + | end |
| 32 | - | sleep(1) |
| 32 | + | rs.setOutput("bottom", false)
|
| 33 | - | os.reboot() |
| 33 | + | |
| 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 |