Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. const char* ssid = "AndroidAP";
  3. const char* password = "00000000";
  4.  
  5. const char* host = "192.168.43.193"; //PROMIJENI!!!!
  6.  
  7. void setup() {
  8. Serial.begin(115200);
  9. delay(100);
  10.  
  11. // We start by connecting to a WiFi network
  12. Serial.println();
  13. Serial.println();
  14. Serial.print("Connecting to ");
  15. Serial.println(ssid);
  16.  
  17. WiFi.begin(ssid, password);
  18.  
  19. while (WiFi.status() != WL_CONNECTED) {
  20. delay(500);
  21. Serial.print(".");
  22. }
  23.  
  24. Serial.println("");
  25. Serial.println("WiFi connected");
  26. Serial.println("IP address: ");
  27. Serial.println(WiFi.localIP());
  28. }
  29.  
  30. void loop() {
  31.  
  32. WiFiClient client;
  33. const int httpPort = 8080; //PROMIJENI!!!!!
  34. if (!client.connect(host, httpPort)) {
  35. Serial.println("connection failed");
  36. return;
  37. }
  38.  
  39.  
  40. String data = "id=66&timeAverage=3859435";
  41.  
  42. Serial.print("Requesting POST: ");
  43. // Send request to the server:
  44. client.println("POST /user HTTP/1.1");
  45. client.println("Host: server_name");
  46. client.println("Accept: */*");
  47. client.println("Content-Type: application/x-www-form-urlencoded");
  48. client.print("Content-Length: ");
  49. client.println(data.length());
  50. client.println();
  51. client.print(data);
  52.  
  53. //delay(5000); // Can be changed
  54. while (client.connected())
  55. {
  56. if (client.available())
  57. {
  58. String line = client.readStringUntil('\n');
  59. Serial.println(line);
  60. }
  61. }
  62. if (client.connected()) {
  63. client.stop(); // DISCONNECT FROM THE SERVER
  64. }
  65. Serial.println();
  66. Serial.println("closing connection");
  67. delay(5000);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement