View difference between Paste ID: mpUffk7p and 9XvpiTgf
SHOW: | | - or go back to the newest paste.
1
--variables
2
stationName = ""
3-
--url = "https://script.google.com/macros/s/AKfycbzoL3L5-Yek4DxZUdNwFtCdS7ec2fzyFRp8ZdaMSlc/exec"
3+
otherStationName = ""
4-
url = "http://cablepost.ddns.net/cc/jackTrainStation"
4+
linkId = ""
5-
if os.getComputerLabel() == "jackstationbottom" then
5+
6-
	other = "jackstationtop"
6+
monitorSide = "top"
7-
	rs = "right"
7+
cartDetectionSide = "bottom"
8-
else
8+
callButtonSide = "left"
9-
	other = "jackstationbottom"
9+
railPowerSide = "front"
10-
	rs = "left"
10+
11
function checkConnection()
12-
print("other: " .. other)
12+
	while type(http.get(url)) ~= "table" do
13-
monitor = peripheral.wrap( "top" )
13+
		print("connection test")
14
	end
15
end
16
17-
	if redstone.getInput("bottom") then
17+
18-
		status = http.get(url .. "/status.php?status=" .. os.getComputerLabel()).readAll()
18+
19
url = "http://tools.uk.ms/cc/trainstations"
20-
		status = http.get(url .. "/status.php").readAll()
20+
monitor = peripheral.wrap( monitorSide  )
21-
		if status == os.getComputerLabel() then
21+
22-
			status = http.get(url .. "/status.php?status=none").readAll()
22+
23
	-- status
24
	if redstone.getInput(cartDetectionSide) then
25-
	status = http.get(url .. "/status.php").readAll()
25+
		checkConnection()
26
		status = http.get(url .. "/status.php?status=" .. stationName .. "&linkid=" .. linkId).readAll()
27
		print("connection error")
28
	else
29-
	c = http.get(url .. "/call.php").readAll()
29+
		checkConnection()
30-
	if c == os.getComputerLabel() then	
30+
		status = http.get(url .. "/status.php" .. "?linkid=" .. linkId).readAll()
31-
		redstone.setOutput("front", true)
31+
		if status == stationName then
32
			checkConnection()
33-
		redstone.setOutput("front", false)
33+
			status = http.get(url .. "/status.php?status=none" .. "&linkid=" .. linkId).readAll()
34
		end
35
	end
36-
	if redstone.getInput(rs) then
36+
	checkConnection()
37-
		c = http.get(url .. "/call.php?call=" .. other).readAll()
37+
	status = http.get(url .. "/status.php?linkid=" .. linkId).readAll()
38
	print(status)
39
	-- call
40
	-- get call
41
	checkConnection()
42
	c = http.get(url .. "/call.php?&linkid=" .. linkId).readAll()
43
	if c == stationName then	
44
		redstone.setOutput(railPowerSide, true)
45
		sleep(1)
46
		redstone.setOutput(railPowerSide, false)
47-
		c = http.get(url .. "/call.php?call=none").readAll()
47+
48
	-- set call
49
	if redstone.getInput(callButtonSide) then
50
		checkConnection()
51
		c = http.get(url .. "/call.php?call=" .. otherStationName .. "&linkid=" .. linkId).readAll()
52-
	if status == "jackstationbottom" then
52+
53-
		monitor.write( "Status: bottom")
53+
54-
	elseif status == "jackstationtop" then
54+
55-
		monitor.write( "Status: top")
55+
56
	else
57-
		monitor.write( "Status: unknown")
57+
58
	end
59
	if callCounter > 2 then
60
		callCounter = 0
61
		checkConnection()
62
		c = http.get(url .. "/call.php?call=none" .. "&linkid=" .. linkId).readAll()
63
	end
64
	print(c)
65
	monitor.clear()
66
	monitor.setCursorPos(1,1)
67
	monitor.write( "Status: " .. status)
68
	monitor.setCursorPos(1,2)
69
	monitor.write( "Call: " .. c)
70
	sleep(1)
71
end