sendYo.lua 779 B

123456789101112131415161718192021222324252627
  1. --This code assumes that the WIFI AP has already been set up
  2. file.open("yorecipient.txt", "r")
  3. print("sending yo to "..file.readline())
  4. file.close()
  5. wifi.sleeptype(wifi.NONE_SLEEP)
  6. wifi.setmode(wifi.STATION)
  7. function generateContentString()
  8. file.open("yorecipient.txt", "r")
  9. return "api_token=0c6ac771-71fa-420f-810c-2853989a8ca6&username="..string.upper(file.readline())
  10. end
  11. local contentString = generateContentString()
  12. local contentLength = string.len(contentString)
  13. http.post(
  14. 'https://api.justyo.co/yo/',
  15. 'Content-Type: application/x-www-form-urlencoded\r\n'..
  16. 'Content-length: ' ..contentLength.. '\r\n',
  17. contentString,
  18. function(code, data)
  19. print("POST REQUEST CALLBACK")
  20. print("code: ", code)
  21. print("data: ", data)
  22. wifi.sleeptype(wifi.LIGHT_SLEEP)
  23. end
  24. )