Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require('event')
- local stem = require('stem')
- local side = require('sides')
- local com = require('component')
- local redstone = com.isAvailable('redstone') and com.redstone or nil
- local channel = "test"
- local layout = [===[
- document.body.innerHTML = "\
- <style>button:active { background: #fac700; }</style>\
- <button onclick=\"sendMessage(\'toggle\')\">Toggle Light</button>\
- ";
- document.body.style.alignItems = "center";
- ]===]
- local lampSide = side.top
- local lampTurnedOn = false
- print("Connecting to the #" .. channel .. " STEM channel...")
- local server = stem.connect('stem.fomalhaut.me')
- server:subscribe(channel)
- print("Done.")
- print("Press [q] to quit.")
- while true do
- local name, a, b = event.pull()
- if name == "stem_message" then
- local message = b
- if message == "connect" then
- print("Someone wants to connect - sending the layout...")
- server:send(channel, layout)
- elseif message == "toggle" then
- if redstone ~= nil then
- if not lampTurnedOn then
- redstone.setOutput(lampSide, 16)
- lampTurnedOn = true
- else
- redstone.setOutput(lampSide, 0)
- lampTurnedOn = false
- end
- end
- end
- elseif name == "key_down" then
- local char = b
- if char == 113 then break end
- end
- end
- server:disconnect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement