init.lua 1.1 KB

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