|
@@ -6,6 +6,7 @@ local pwm_pin = 1
|
|
|
local pwm_timer = 1
|
|
local pwm_timer = 1
|
|
|
local pwm_freq = 500
|
|
local pwm_freq = 500
|
|
|
local pwm_max_bright = 1023
|
|
local pwm_max_bright = 1023
|
|
|
|
|
+local config = nil -- sensitive data loaded at runtime
|
|
|
|
|
|
|
|
function debounce (func)
|
|
function debounce (func)
|
|
|
local last = 0
|
|
local last = 0
|
|
@@ -21,7 +22,29 @@ function debounce (func)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function onChange ()
|
|
function onChange ()
|
|
|
- print('LYFT OFF!')
|
|
|
|
|
|
|
+ print('LYFT OFF!')
|
|
|
|
|
+ http.post(
|
|
|
|
|
+ 'https://api.lyft.com/oauth/token',
|
|
|
|
|
+ 'Content-Type: application/json',
|
|
|
|
|
+ '{"grant_type": "refresh_token", "refresh_token": "' .. config.refresh_token .. '"}',
|
|
|
|
|
+ function(code, data)
|
|
|
|
|
+ debug_message('refresh status code: ' .. (code or 'nil'))
|
|
|
|
|
+ debug_message('refresh resp data: ' .. (data or 'nil'))
|
|
|
|
|
+
|
|
|
|
|
+ openBrace, closeBrace = string.find(data, '^{.*}')
|
|
|
|
|
+ json_data = cjson.decode(string.sub(data, openBrace, closeBrace))
|
|
|
|
|
+ for k,v in pairs(json_data) do print(k, v) end
|
|
|
|
|
+
|
|
|
|
|
+ http.get(
|
|
|
|
|
+ 'https://maker.ifttt.com/trigger/lyftoff/with/key/' .. config.ifttt_event_key,
|
|
|
|
|
+ nil,
|
|
|
|
|
+ function(code, data)
|
|
|
|
|
+ debug_message('status code: ' .. (code or 'nil'))
|
|
|
|
|
+ debug_message('resp data: ' .. (data or 'nil'))
|
|
|
|
|
+ end
|
|
|
|
|
+ )
|
|
|
|
|
+ end
|
|
|
|
|
+ )
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function startServer()
|
|
function startServer()
|
|
@@ -59,11 +82,17 @@ end
|
|
|
function onStart()
|
|
function onStart()
|
|
|
debug_message('onStart')
|
|
debug_message('onStart')
|
|
|
|
|
|
|
|
- -- register PWM and set low
|
|
|
|
|
- -- tmr.unregister(pwm_timer)
|
|
|
|
|
|
|
+ debug_message('onStart: reading config')
|
|
|
|
|
+ file.open('config.json')
|
|
|
|
|
+ config = cjson.decode(file.read())
|
|
|
|
|
+ file.close()
|
|
|
|
|
+
|
|
|
|
|
+ debug_message('onStart: enable pwm')
|
|
|
pwm.setup(pwm_pin, pwm_freq, 0)
|
|
pwm.setup(pwm_pin, pwm_freq, 0)
|
|
|
pwm.start(pwm_pin)
|
|
pwm.start(pwm_pin)
|
|
|
- -- pwm.stop(pwm_pin)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ debug_message('onStart: connecting')
|
|
|
|
|
+ wifi.sta.config(config.ssid, config.pwd)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function pwm_fadein()
|
|
function pwm_fadein()
|