Bladeren bron

preliminary of rewrite - exploring modules and scope

etisab 10 jaren geleden
bovenliggende
commit
8836fcb4c4
4 gewijzigde bestanden met toevoegingen van 40 en 2 verwijderingen
  1. 1 2
      build/wifiSetup.lua
  2. 3 0
      rebuild/init.lua
  3. 11 0
      rebuild/main.lua
  4. 25 0
      rebuild/yo.lua

+ 1 - 2
build/wifiSetup.lua

@@ -108,11 +108,10 @@ function setupServer()
       if updated and wifi.sta.status() == 5 then
         
         debugMsg("updated and connected")
-        tmr.alarm(SUCCESS_SETUP_TIMER, 1000, tmr.ALARM_SINGLE, function()
+        tmr.alarm(SUCCESS_SETUP_TIMER, 3000, tmr.ALARM_SINGLE, function()
           debugMsg("closing AP")
           stopBroadcastAP()
         end)
-
       end
     end)
   end)

+ 3 - 0
rebuild/init.lua

@@ -0,0 +1,3 @@
+tmr.alarm(0, 1000, 0, function()
+  dofile('main.lua')
+)

+ 11 - 0
rebuild/main.lua

@@ -0,0 +1,11 @@
+require 'yo'
+
+DEBUG = true
+a = '0c6ac771-71fa-420f-810c-2853989a8ca6'
+y = 'ariyeah'
+
+function debug(message)
+  if DEBUG then
+    print(message)
+  end
+end

+ 25 - 0
rebuild/yo.lua

@@ -0,0 +1,25 @@
+module(..., package.seeall)
+
+function yo(yo_user, api_token)
+  assert(type(yo_user) == 'string', 'yo_user must be a string')
+  assert(type(api_token) == 'string', 'api_token must be a string')
+  assert(yo_user ~= '', 'yo_user must not be empty string')
+  assert(api_token ~= '', 'api_token must not be empty string')
+
+  local contentString = "api_token=" .. api_token .. "&username="..string.upper(yo_user)
+  local contentLength = string.len(contentString)
+
+  debug('yo.yo: sending Yo')
+  wifi.sleeptype(wifi.NONE_SLEEP)
+  http.post(
+    'https://api.justyo.co/yo/',
+    'Content-Type: application/x-www-form-urlencoded\r\n' ..
+    'Content-length: ' .. contentLength .. '\r\n',
+    contentString,
+    function(status_code, response_data)
+      wifi.sleeptype(wifi.LIGHT_SLEEP)
+      debug('yo.yo: status code ' .. status_code)
+      debug('yo.yo: response data ' .. response_data)
+    end
+  )
+end