main.lua 814 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. DEBUG = true
  2. function debug_message(message)
  3. if DEBUG then
  4. print(message)
  5. end
  6. --TODO: rolling last 10
  7. end
  8. local yo = require('yo')
  9. local server = require('server')
  10. local read = require('read')
  11. function wifi_setup(func, ...)
  12. wifi.setmode(wifi.STATIONAP)
  13. wifi.ap.config({
  14. ssid = "YoButton-" .. node.chipid(),
  15. pwd = "yobutton",
  16. max = 1,
  17. auth = wifi.AUTH_OPEN
  18. })
  19. wifi.ap.dhcp.start()
  20. wifi.sleeptype(wifi.NONE_SLEEP)
  21. func(...)
  22. --TODO wifi_setup inactivity timeout
  23. end
  24. function wifi_default(func, ...)
  25. server.stop()
  26. wifi.setmode(wifi.STATION)
  27. wifi.sleeptype(wifi.NONE_SLEEP)
  28. func(...)
  29. wifi.sleeptype(wifi.MODEM_SLEEP)
  30. end
  31. function short_press()
  32. wifi_default(yo.yo, read.yo_recipient(), read.api_key())
  33. end
  34. function long_press()
  35. wifi_setup(server.start)
  36. end