Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3. int pressurePin = A0;
  4. int force;
  5. int LEDpin = 0;
  6. int mapValue = 0;
  7. int count = 0;
  8.  
  9. const char* ssid = "cisc340";
  10. const char* password = "L0gica1@";
  11.  
  12. const char* host = "https://72d6dc2b.ngrok.io";
  13.  
  14. void setup() {
  15. Serial.begin(115200);
  16. delay(100);
  17. pinMode(LEDpin, OUTPUT);
  18.  
  19. // We start by connecting to a WiFi network
  20.  
  21. Serial.println();
  22. Serial.println();
  23. Serial.print("Connecting to ");
  24. Serial.println(ssid);
  25.  
  26. WiFi.begin(ssid, password);
  27.  
  28. while (WiFi.status() != WL_CONNECTED) {
  29. delay(500);
  30. Serial.print(".");
  31. }
  32.  
  33. Serial.println("");
  34. Serial.println("WiFi connected");
  35. Serial.println("IP address: ");
  36. Serial.println(WiFi.localIP());
  37. }
  38.  
  39. int value = 0;
  40.  
  41. void loop() {
  42.  
  43. delay(5000);
  44. ++value;
  45.  
  46. Serial.print("connecting to ");
  47. Serial.println(host);
  48.  
  49. // Use WiFiClient class to create TCP connections
  50. WiFiClient client;
  51. const int httpPort = 80;
  52. if (!client.connect(host, httpPort)) {
  53. Serial.println("connection failed");
  54. return;
  55. }
  56.  
  57. // We now create a URI for the request
  58. String url = "/test";
  59. Serial.print("Requesting URL: ");
  60. Serial.println(url);
  61.  
  62. // This will send the request to the server
  63. client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  64. "Host: " + host + "\r\n" +
  65. "Connection: close\r\n\r\n");
  66. delay(500);
  67.  
  68. // Read all the lines of the reply from server and print them to Serial
  69. while(count <= 500){
  70. force = analogRead(pressurePin);
  71. mapValue = map(force, 0, 1023, 0, 100000);
  72. Serial.println(mapValue);
  73. digitalWrite(LEDpin, HIGH);
  74. delay(100);
  75. digitalWrite(LEDpin, LOW);
  76. delay(100);
  77. // String line = client.readStringUntil('\r');
  78. // Serial.print(line);
  79. count++;
  80. }
  81.  
  82. Serial.println();
  83. Serial.println("closing connection");
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement