Jelajahi Sumber

terminate requests. pwm on start. send IP with notification

etisab 10 tahun lalu
induk
melakukan
23c03537bb
1 mengubah file dengan 14 tambahan dan 9 penghapusan
  1. 14 9
      main.lua

+ 14 - 9
main.lua

@@ -37,25 +37,29 @@ function on_change()
   --   'https://api.lyft.com/oauth/token',
   --   'Content-Type: application/json\r\n'
   --   .. 'Authorization: Basic ' .. config.base64_auth .. '\r\n',
-  --   '{"grant_type": "refresh_token", "refresh_token": "' .. config.refresh_token .. '"}',
+  --   '{"grant_type": "refresh_token", "refresh_token": "' .. config.refresh_token .. '"}\r\n\r\n',
   --   function(code, data)
   --     debug_message('token refresh status code: ' .. (code or 'nil'))
   --     debug_message('token refresh resp data: ' .. (data or 'nil'))
 
+  --     json_data = jsonify(data)
+
       debug_message('Requesting ride')
       http.post(
         'https://api.lyft.com/v1/rides',
-        'Authorization: Bearer ' .. 'SANDBOX-gAAAAABW0edPpkkTOzW3w0vo5DE-bgHGD53Hz-kehlw-FWMQw72YqmbOPYlenvnEtRLg-Ru025J0zHhPR443buu6Wr6-ipcChddXUfgeeYZUu5ZFZpjicEiwdFiBl0Y6lklBVQTMtc2BiosI9nC2SFkAuL28PSIAQpgCISDKNdYopoaQjg5nYGIQ210isODJ7o451tkeUJE5vv2Pmq-nxfKlTQK5LPwFvQ-MHUBRHZezdPBtXA0uQ-xamxPuz7eWbNUJqbeVsqZlsVxcN21YYC5I4nolkuUlnmfAVfMFJcam6DrQOVVKz6E=' .. '\r\n'
+        'Authorization: Bearer ' .. 'SANDBOX-gAAAAABW0mvDUr9fc7Vgw6GF7Jv7ps5KRWw0sqd4jrg-p-tetlI5iL2ulbctnlV6y58B2mvOUrR7Huk13kQ2uhqrwV9vfK_BLTQ7vLynJSD0Y9Uw1UgpIyZeDV2q0RQ7Sxtf0-qTPgaXQyFLmUZDW-teuE6KTjv6srJ2naEMGe-QtAJnpLdrnw9ZDsB0RJwpK9Heq6Vbt3j4aXvXtacvprZ1S1oU8JIZ7IWbcoTVu4GkcvxFq6OFvRauUR1nTorQOk49h-bx_iKxd_pp2G7ZgyYLwFsPojpied_y17RLhGntMYQKH0yZvo0=' .. '\r\n'
         .. 'Content-Type: application/json\r\n',
-        '{"ride_type" : "lyft", "origin" : {"lat" : 37.804427, "lng" : -122.429473 } }',
+        '{"ride_type" : "lyft", "origin" : {"lat" : 37.804427, "lng" : -122.429473 } }\r\n\r\n',
         function(code, data)
           debug_message('ride request status code: ' .. (code or 'nil'))
           debug_message('ride request resp data: ' .. (data or 'nil'))
 
           debug_message("Sending IFTTT notification")
-          http.get(
+          ip = wifi.sta.getip()
+          http.post(
             'https://maker.ifttt.com/trigger/lyftoff/with/key/' .. config.ifttt_event_key,
-            nil,
+            'Content-Type: application/json\r\n',
+            '{"value1": "' .. ip .. '"}\r\n\r\n',
             function(code, data)
               debug_message('ifttt status code: ' .. (code or 'nil'))
               debug_message('ifttt resp data: ' .. (data or 'nil'))
@@ -114,15 +118,16 @@ function on_start()
   config = cjson.decode(file.read())
   file.close()
 
-  debug_message('on_start: enable pwm')
-  pwm.setup(pwm_pin, pwm_freq, 0)
-  pwm.start(pwm_pin)
-
   debug_message('on_start: connecting')
   wifi.sta.config(config.ssid, config.pwd)
 
   debug_message('on_start: starting server to receive pushes')
   start_server()
+
+  debug_message('on_start: enable pwm')
+  pwm.setup(pwm_pin, pwm_freq, 0)
+  pwm.start(pwm_pin)
+  pwm_fadein()
 end
 
 function pwm_fadein()