Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- int pressurePin = A0;
- int force;
- int LEDpin = 0;
- int mapValue = 0;
- int count = 0;
- const char* ssid = "cisc340";
- const char* password = "L0gica1@";
- const char* host = "https://72d6dc2b.ngrok.io";
- void setup() {
- Serial.begin(115200);
- delay(100);
- pinMode(LEDpin, OUTPUT);
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- int value = 0;
- void loop() {
- delay(5000);
- ++value;
- Serial.print("connecting to ");
- Serial.println(host);
- // Use WiFiClient class to create TCP connections
- WiFiClient client;
- const int httpPort = 80;
- if (!client.connect(host, httpPort)) {
- Serial.println("connection failed");
- return;
- }
- // We now create a URI for the request
- String url = "/test";
- Serial.print("Requesting URL: ");
- Serial.println(url);
- // This will send the request to the server
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Connection: close\r\n\r\n");
- delay(500);
- // Read all the lines of the reply from server and print them to Serial
- while(count <= 500){
- force = analogRead(pressurePin);
- mapValue = map(force, 0, 1023, 0, 100000);
- Serial.println(mapValue);
- digitalWrite(LEDpin, HIGH);
- delay(100);
- digitalWrite(LEDpin, LOW);
- delay(100);
- // String line = client.readStringUntil('\r');
- // Serial.print(line);
- count++;
- }
- Serial.println();
- Serial.println("closing connection");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement