init.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --[[ ASSUMPTIONS
  2. yorecipient.txt exists
  3. apikey.txt exists and contains a valid API key
  4. ]]
  5. VERSION = '0.1.0'
  6. DEBUG = true
  7. SETUP = false
  8. SETUP_TIMEOUT = 300000
  9. STARTUP_DELAY_TIMER = 0
  10. INTERRUPT_TIMER = 1
  11. INDEX_TIMER = 2
  12. SETUP_INACTIVITY_TIMER = 3
  13. WIFI_WAIT_TIMER = 4
  14. SUCCESS_SETUP_TIMER = 5
  15. YO_RECIPIENT = nil
  16. API_KEY = nil
  17. buttonPin = 6 -- GPIO12
  18. ledPin = 2 --GPIO4
  19. function debugMsg(msg)
  20. print("Yo debug: " .. msg)
  21. end
  22. function init()
  23. debugMsg("Starting.")
  24. wifi.setmode(wifi.STATION)
  25. debugMsg('Booting button ' .. node.chipid())
  26. debugMsg('Version ' .. VERSION)
  27. yoRecipientExists = file.open('yorecipient.txt', 'r')
  28. YO_RECIPIENT = file.read()
  29. file.close()
  30. if YO_RECIPIENT then
  31. YO_RECIPIENT = string.gsub(YO_RECIPIENT, '\n', '')
  32. YO_RECIPIENT = string.gsub(YO_RECIPIENT, ' ', '')
  33. end
  34. debugMsg('found recipient:' .. tostring(YO_RECIPIENT) .. '.')
  35. file.open('apikey.txt', 'r')
  36. API_KEY = file.read()
  37. file.close()
  38. debugMsg('api key: ' .. API_KEY)
  39. dofile("interrupt.lua")
  40. end
  41. if DEBUG then
  42. debugMsg("3 second startup delay using timer " .. STARTUP_DELAY_TIMER .. '...')
  43. tmr.alarm(STARTUP_DELAY_TIMER, 3000, 0, init)
  44. else
  45. debugMsg("initializing...")
  46. init()
  47. end