Advertisement
Lupino

control.lua

Jul 8th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local redstone = component.proxy(component.list("redstone")())
  2. local internet = component.proxy(component.list("internet")())
  3.  
  4. local uuid = '12839855-d8e4-4149-891d-8dfafed21731'
  5. local token = '9e899f11-1560-458b-8492-2723a2374d8a'
  6. local url = 'http://superapp.huabot.com/api/devices/' .. uuid .. '/rpc/'
  7. local id = '1'
  8.  
  9. function relaySwitch(onoff)
  10.     local command = '%7B%22method%22%3A%22relay_' .. onoff .. '%22%2C%22index%22%3A' .. id .. '%7D'
  11.     local data = 'data=' .. command .. '&token=' .. token .. '&format=json'
  12.     local ret, res = pcall(internet.request, url, data)
  13.     return ret
  14. end
  15.  
  16. local switch = 4
  17. local state = true
  18.  
  19. while true do
  20.     computer.pullSignal(1)
  21.     if (redstone.getInput(switch) > 2) then
  22.         if not state then
  23.             state = relaySwitch('on')
  24.         end
  25.     else
  26.         if state then
  27.             state = relaySwitch('off')
  28.         end
  29.     end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement