Skip to content

Instantly share code, notes, and snippets.

@ckdake
Created May 14, 2022 01:34
Show Gist options
  • Save ckdake/98ea451e2beff9cb7067b0f3af04fd09 to your computer and use it in GitHub Desktop.
Save ckdake/98ea451e2beff9cb7067b0f3af04fd09 to your computer and use it in GitHub Desktop.
import time
import board
import digitalio
import web
status = False
relay = digitalio.DigitalInOut(board.D26)
relay.direction = digitalio.Direction.OUTPUT
relay.value = False
urls = (
'/(.*)', 'call'
)
class call:
global status
def GET(self, action):
global status
if (action == 'status'):
if status:
return 1
else:
return 0
return "Beep bo beep!"
def POST(self, action):
global status
if (action == 'on'):
status = True
relay.value = status
elif (action == 'off'):
status = False
relay.value = status
return "Beep bo beep beep!"
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment