init.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. debugMsg('Booting button ' .. node.chipid())
  23. yoRecipientExists = file.open('yorecipient.txt', 'r')
  24. YO_RECIPIENT = file.read()
  25. file.close()
  26. if YO_RECIPIENT then
  27. YO_RECIPIENT = string.gsub(YO_RECIPIENT, '\n', '')
  28. YO_RECIPIENT = string.gsub(YO_RECIPIENT, ' ', '')
  29. end
  30. debugMsg('found recipient:' .. tostring(YO_RECIPIENT) .. '.')
  31. apiKeyExists = file.open('apikey.txt', 'r')
  32. API_KEY = file.read()
  33. file.close()
  34. debugMsg('api key: ' .. API_KEY)
  35. dofile("interrupt.lua")
  36. end)