read.lua 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local wifi = wifi
  2. local file = file
  3. local yo_file = 'yorecipient.txt'
  4. local wifi_status = {
  5. [0] = 'not enabled',
  6. 'connecting',
  7. 'wrong password',
  8. 'network not found',
  9. 'connection fail',
  10. 'connected'
  11. }
  12. local debug_message = debug_message
  13. module(...)
  14. function yo_recipient()
  15. debug_message('read.yo_recipient')
  16. if file.exists(yo_file) == false then
  17. debug_message('creating file')
  18. file.open(yo_file, 'w+')
  19. file.write('')
  20. file.close()
  21. else
  22. debug_message('file exists')
  23. file.open(yo_file)
  24. yo = file.read()
  25. file.close()
  26. end
  27. return (yo or '')
  28. end
  29. function api_key()
  30. file.open('apikey.txt')
  31. local api_key = file.read()
  32. file.close()
  33. return api_key
  34. end
  35. function current_settings()
  36. return {
  37. yo_to = yo_recipient(),
  38. ssid = wifi.sta.getconfig(),
  39. status = wifi_status[wifi.sta.status()]
  40. }
  41. end
  42. function index()
  43. --TODO determine tradeoff of hardcoding index.html
  44. file.open('index.html')
  45. local index = file.read()
  46. file.close()
  47. return index
  48. end