1
Good afternoon. I’m developing a project with Arduino to perform the pulse count when a request via an HTTP web socket created by Arduino ESP32 is triggered. The request (in this case, when the user presses the button on the page) to start the count is already implemented via GET/H. However, I would like to add on the page, using HTML, a field where I could write a value, and this value could be used by the program in Arduino. I have no deep knowledge of HTML and front end, nor how to integrate it into the Arduino, so I would like to know if this is feasible, and if there is any specific material for this type of study.
In the code below I would like to add a variable "time" that is read on the server via html to be used in the counting of pulses.
//RUNS THE WEB SERVER AND COUNT THE PULSES DURING A SPECIFIED TIME
void loop(){
WiFiClient client;
client = server.available(); // listen for incoming clients
//CONNECT TO SERVER
if (client){ // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()){ // loop while the client's connected
if (client.available()){ // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n'){ // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0){
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("Click <a href=\"/H\">here</a> to begin counter");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
}
else{ // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
//READS THE REQUEST AND COUNT THE PULSES
// Check to see if the client request was "GET /H":
if (currentLine.endsWith("GET /H")) {
while(timer <= tempo){
timer = 0;
if (timer > tempo){
break;
}
timer = millis();
//Serial.println(timer);
delay(25);
if (digitalRead(pin) > var){
var = 1;
pulse++;
Serial.print(pulse);
Serial.println(" pulses detected");
while (digitalRead(pin) == HIGH);
}
else if (digitalRead(pin) == 0){
var = 0;
}
delay(1);
}
//CONNECT TO IFTTT TO WRITE ON GOOGLE SHEETS
initIFTTTrequest();
}
}
}
// close the connection:
client.stop();
Serial.println("Client Disconnected.");
}
}