init.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = 120000
  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. print("3 second startup delay using timer " .. STARTUP_DELAY_TIMER .. '...')
  20. tmr.alarm(STARTUP_DELAY_TIMER, 3000, 0, function ()
  21. print("Starting.")
  22. function debugMsg(msg)
  23. print("Yo debug: " .. msg)
  24. end
  25. wifi.setmode(wifi.STATION)
  26. debugMsg('Booting button ' .. node.chipid())
  27. debugMsg('Version ' .. VERSION)
  28. yoRecipientExists = file.open('yorecipient.txt', 'r')
  29. YO_RECIPIENT = file.read()
  30. file.close()
  31. if YO_RECIPIENT then
  32. YO_RECIPIENT = string.gsub(YO_RECIPIENT, '\n', '')
  33. YO_RECIPIENT = string.gsub(YO_RECIPIENT, ' ', '')
  34. end
  35. debugMsg('found recipient:' .. tostring(YO_RECIPIENT) .. '.')
  36. apiKeyExists = file.open('apikey.txt', 'r')
  37. API_KEY = file.read()
  38. file.close()
  39. debugMsg('api key: ' .. API_KEY)
  40. dofile("interrupt.lua")
  41. end)