View difference between Paste ID: jrzXpsgU and cb2uJ8jk
SHOW: | | - or go back to the newest paste.
1
print("Capacitor Reader Client")
2
local channel = 70
3
4
local rsSide = "back"
5
local rsDefault = false
6
rs.setOutput(rsSide, rsDefault)
7
8
local capacityToActivate = 2
9
local refilling = false
10
11
local secretWord = "himama"
12
local secretWord2 = "hidada"
13
14
local modem = peripheral.wrap("left")
15
if (not modem) then
16
    print("Please connect a modem")
17
else
18
    print("Connecting with the host...")
19
    modem.transmit(channel, 1, secretWord)
20
    
21
    modem.open(channel)
22
    while true do
23
        local sub0, sub1, sub2, sub3, message, sub4 = os.pullEvent("modem_message")
24
        
25
        if message == secretWord2 then
26
            print("Connected")
27
            
28
            while true do
29
                local sub00, sub11, sub22, sub33, status = os.pullEvent("modem_message")
30
                local receivedStatus = tonumber(status)
31
                print("Received Status: " .. receivedStatus)
32
                
33
                if (receivedStatus < capacityToActivate) and not refilling then
34
                    rs.setOutput(rsSide, not rsDefault)
35
                    refilling = true
36
                end
37
                if (receivedStatus >= 14) and refilling then
38
                    rs.setOutput(rsSide, rsDefault)
39
                    refilling = false
40
                end
41
            end
42
        else
43
            print("WRONG PASSWORD, exiting..")
44
            break
45
        end
46
    end
47
    modem.close(channel)
48
end