Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3. const char* ssid = "BELL473";
  4. const char* password = "XXXXXXX";
  5.  
  6. const char* host = "ns8451.hostgator.com";
  7.  
  8. void setup() {
  9. Serial.begin(115200);
  10. delay(10);
  11.  
  12. // We start by connecting to a WiFi network
  13.  
  14. Serial.println();
  15. Serial.println();
  16. Serial.print("Connecting to ");
  17. Serial.println(ssid);
  18.  
  19. WiFi.begin(ssid, password); //works!
  20.  
  21. while (WiFi.status() != WL_CONNECTED) {
  22. delay(500);
  23. Serial.print(".");
  24. }
  25.  
  26. Serial.println("");
  27. Serial.println("WiFi connected");
  28. Serial.println("IP address: ");
  29. Serial.println(WiFi.localIP());
  30. }
  31.  
  32. int value = 0;
  33.  
  34. void loop() {
  35. delay(5000);
  36. ++value;
  37.  
  38. Serial.print("connecting to ");
  39. Serial.println(host);
  40.  
  41. // Use WiFiClient class to create TCP connections
  42. WiFiClient client;
  43. const int httpPort = 80;
  44. if (!client.connect(host, httpPort)) { //works!
  45. Serial.println("connection failed");
  46. return;
  47. }
  48.  
  49. // We now create a URI for the request
  50. String url = "/GetData.php";
  51. url += "?username=";
  52. url += "aaaa";
  53. url += "&pin=";
  54. url += "bbbb";
  55. url += "&cost=";
  56. url += "cccc";
  57.  
  58. Serial.print("Requesting URL: ");
  59. Serial.println(url);
  60.  
  61. // This will send the request to the server
  62. client.print(String("GET ") + url + " HTTP/1.1rn" +
  63. "Host: " + host + "rn" +
  64. "Connection: closernrn");
  65.  
  66. Serial.println();
  67. Serial.println("closing connection");
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement