sendYo.lua 964 B

12345678910111213141516171819202122232425262728293031
  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. function generateContentString()
  7. file.open("yorecipient.txt", "r")
  8. return "api_token=0c6ac771-71fa-420f-810c-2853989a8ca6&username="..string.upper(file.readline())
  9. end
  10. wifi.setmode(wifi.STATION)
  11. sk = nil
  12. sk = net.createConnection(net.TCP,0)
  13. sk:on("receive", function(sck, c)
  14. print(c)
  15. wifi.sleeptype(wifi.MODEM_SLEEP)
  16. end)
  17. sk:on("connection", function(sk, payload)
  18. contentString = generateContentString()
  19. strlen = string.len(contentString)
  20. sk:send("POST /yo/ HTTP/1.1\r\n"
  21. .."Host: api.justyo.co\r\n"
  22. .."Connection: close\r\n"
  23. .."Content-Length: "..strlen.."\r\n"
  24. .."Accept: */*\r\n"
  25. .."Content-type: application/x-www-form-urlencoded\r\n\r\n"
  26. ..contentString)
  27. end)
  28. sk:connect(80, "api.justyo.co")