init.lua 1.0 KB

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