Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Script: PDA Reactor Controller (Big Reactors) (RECEIVER PC)
- Author: csmit195
- Server: Toasty Networks - Tekkit Legends
- For usage by: namar4777
- Description: Script remotely controls Reactor via Pocket Computer regardless of distance using HTTP Post API. The code relies on regularily checking for status updates.
- Technologies used:
- * Lua / ComputerCraft
- * NodeJS DataStore server(offering as a free service)
- Potential Future Upgrades:
- Remote mobile / web app controller as long as reactor is chunk loaded.
- ]]
- -- Configuration Settings
- local cfg = {
- ['redstoneSide'] = 'right',
- ['autoUpdate'] = true
- }
- -- Cache Variables
- local currentReactorState = rs.getOutput(cfg.redstoneSide)
- function initiate()
- while true do
- print('loop start')
- local reactorRequest = http.get('http://45.76.117.50:8080/datastore/get/namar_reactor/state')
- local requestContent = reactorRequest.readAll()
- local reactorState = requestContent == 'error:nostore' or requestContent == 'true' or false
- print('state:'..tostring(reactorState))
- print('raw:'..requestContent)
- if ( currentReactorState ~= reactorState ) then
- print('passed IF')
- setReactorState(reactorState)
- end
- print('loop end')
- reactorRequest.close()
- sleep(10)
- end
- end
- function setReactorState(bool)
- rs.setOutput(cfg.redstoneSide, bool)
- currentReactorState = bool
- print('state changed to:'..tostring(bool))
- end
- function toggleReactorState()
- setReactorState(not rs.getOutput(cfg.redstoneSide))
- end
- initiate()
Advertisement
Add Comment
Please, Sign In to add comment