Browse Source

API keys from file

etisab 10 năm trước cách đây
mục cha
commit
3b0f0c681d
2 tập tin đã thay đổi với 18 bổ sung12 xóa
  1. 17 11
      BUILD/init.lua
  2. 1 1
      BUILD/sendYo.lua

+ 17 - 11
BUILD/init.lua

@@ -14,20 +14,26 @@ WIFI_WAIT_TIMER = 4
 SUCCESS_SETUP_TIMER = 5
 
 YO_RECIPIENT = nil
+API_KEY = nil
 
 print("3 second startup delay using timer " .. STARTUP_DELAY_TIMER .. '...')
 tmr.alarm(STARTUP_DELAY_TIMER, 3000, 0, function ()
-    print("Starting.")
+  print("Starting.")
 
-    function debugMsg(msg)
-      print("Yo debug: " .. msg)
-    end
+  function debugMsg(msg)
+    print("Yo debug: " .. msg)
+  end
 
-    -- yo recipient file must exist
-    yoRecipientExists = file.open('yorecipient.txt', 'r')
-    YO_RECIPIENT = file.read()
-    file.close()
-    debugMsg('found recipient: ' .. tostring(YO_RECIPIENT))
+  -- yo recipient file must exist
+  yoRecipientExists = file.open('yorecipient.txt', 'r')
+  YO_RECIPIENT = file.read()
+  file.close()
+  debugMsg('found recipient: ' .. tostring(YO_RECIPIENT))
 
-    dofile("interrupt.lua")
-  end)
+  apiKeyExists = file.open('apikey.txt', 'r')
+  API_KEY = file.read()
+  file.close()
+  debugMsg('api key: ' .. API_KEY)
+
+  dofile("interrupt.lua")
+end)

+ 1 - 1
BUILD/sendYo.lua

@@ -3,7 +3,7 @@ wifi.setmode(wifi.STATION)
 
 if YO_RECIPIENT then
 	debugMsg('sending yo to ' .. YO_RECIPIENT)
-	local contentString = "api_token=0c6ac771-71fa-420f-810c-2853989a8ca6&username="..string.upper(YO_RECIPIENT)
+	local contentString = "api_token=" .. API_KEY .. "&username="..string.upper(YO_RECIPIENT)
 	local contentLength = string.len(contentString)
 
 	http.post(