Receiving a number from web page

Hello everyone :slight_smile:
Am trying to a receive a number on my "ESP8266 Thing" from an html page via http request and print it on the serial monitor.
I have combined 2 sketch i found on the web and made my own it does the following:
1- turns a led on or off .
2-displays the value of a variable "analogue pin".
3-displays the state of the led on or off.
I have made a container that i can write numbers in it and use a send button on the web page to store it in a function called ('sendValue(val)').
My problem is i don't know how to convert the value inside this function and use it for example to set a Temperature or display it on the serial monitor.
If u could help :frowning: i would gladly appreciate it ;D .
Thanks.

// Required libraries
#include <ESP8266WiFi.h>

// WiFi parameters
const char ssid[] = "******";//wifi username
const char password[] = "******";//wifi pass
const int ANALOG_PIN = A0; // The only analog pin on the Thing
//const int DIGITAL_PIN = 12; // Digital pin to be read

// Create an instance of the server
WiFiServer server(80);

// Pin
int output_pin = 5;

void setup() {
 
  // Start Serial
  Serial.begin(115200);
  delay(10);

  pinMode(output_pin, OUTPUT);
  digitalWrite(output_pin, LOW);
 
  // Connect to 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");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
 
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
 
  // Match the request
  if (req.indexOf("/on") != -1){
    digitalWrite(output_pin, HIGH);
    Serial.println("on led");
  }
  if (req.indexOf("/off") != -1) {
    digitalWrite(output_pin, LOW);
    Serial.println("off led");
  }
   /*if (req.indexOf("flash") != -1) {
    digitalWrite(output_pin, LOW);
    delay(500);
    digitalWrite(output_pin, HIGH);
    Serial.println("flash led");
  }*/
 /*  if (req.indexOf("/sendValue(val)") != -1) {
    char z="sendValue(val)";
    Serial.println(z);
    digitalWrite(output_pin, LOW);
    delay(500);
    digitalWrite(output_pin, HIGH);
    Serial.println("flash led");
  }
   */
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";

  s += "<head>";
  s += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
  s += "<script src=\"https://code.jquery.com/jquery-2.1.3.min.js\"></script>";
  s += "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\">";
  s += "<META HTTP-EQUIV=refresh CONTENT=8>";
  s += "</head>";
  s += "<div class=\"container\">";
  s += "<h2>Door Control</h2>";
  s += "<input type='hidden' name='pin_status' id='pin_status' value='" + String(digitalRead(output_pin)) + "' />";
  s += "<div class='row'>";
  s += "<div class=\"col-md-2\"><input class=\"btn btn-block btn-lg btn-primary\" type=\"button\" value=\"On\" onclick=\"on()\"></div>";
  s += "<div class=\"col-md-2\"><input class=\"btn btn-block btn-lg btn-danger\" type=\"button\" value=\"Off\" onclick=\"off()\"></div>";
  //s += "<div class=\"col-md-2\"><input class=\"btn btn-block btn-lg btn-green\" type=\"button\" value=\"flash\" onclick=\"flash()\"></div>";
  s += "</div></div>";
  s += "
";
  s += "<div class='row'>";
  s += "<div class='col-md-3'>";
  s += "<h4>Analog Pin = <h4>";
  s += "</div>";
  s += "<div class='col-md-3'>";
  s += "<input type='button' class='btn btn-default btn-block' value='" + String(analogRead(ANALOG_PIN)) + "' />";
  s += "</div>";
  s += "<div class='col-md-3'>";
  s += "<input type='number' place-holder='input value' id='val_to_send' class='form-control' style='width:100%' />";
  s += "</div>";
  s += "<div class='col-md-3'>";
  s += "<input type='button' class='btn btn-default btn-block' value='Send' onClick=\"sendValue($('#val_to_send').val());\" />";
  s += "</div>";
  s += "</div>";
  //s += "Analog Pin = ";
  //s += String(analogRead(ANALOG_PIN));
  s += "
"; // Go to the next line.
  s += "<div id='pin_status_result'></div>";
  //s += String(digitalRead(output_pin));
  
  s += "<script>";
  s += "$(document).ready(function()";
  s +="{";
  s += "if($('#pin_status').val() == '1'){";
  s += "$('#pin_status_result').text('Digital Pin 5 = ON');";
  s += "}else{";
  s += "$('#pin_status_result').text('Digital Pin 5 = OFF');";
  s += "}";
  s += "});";
  s += "function on()"; 
  s += "{";
  s += "$.get('on');";
  s += "}";
  s += "function off()"; 
  s += "{";
  s += "$.get('off');";
  s += "}";
  s += "function flash()";
  s += "{";
  s += "$.get('flash');";
  s += "}";
  s += "function sendValue(val)";
  s += "{";
  s += "$.get('sendValue(val)');";
  s += "}";
  s += "</script>";

  
  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disconnected");
}
    char z="sendValue(val)";

What is this nonsense? You can not assign a string to a char.

My problem is i don't know how to convert the value inside this function and use it for example to set a Temperature or display it on the serial monitor.

You do NOT have a function called sendValue(). So, the rest of that statement makes no sense.

PaulS:

    char z="sendValue(val)";

What is this nonsense? You can not assign a string to a char.
You do NOT have a function called sendValue(). So, the rest of that statement makes no sense.

Yea i already knew it was dumb that i comment it.
Am not that good in this so i just do whatever i can, as far as i know the value i write in the box and press send will be store in this variable sendValue(val) in the web side of this so how to get the number from it.
Thanks in advance

as far as i know the value i write in the box and press send will be store in this variable sendValue(val) in the web side of this

sendValue(val) is NOT a variable. You can't get a value from it.

The only reference to sendValue() in your code is in the onClick() handler for the button object. What that means is that the object will call the sendValue() method when that particular button is clicked. What that does is cause a name/value pair to be added to the GET request that the browser makes.

You need to parse the complete GET request, looking for the name/value pair (specifically for the name), then look for the delimiter that marks the end of the name/value pair (the end of the request or a &). Copy the data after the name and equals sign, before the delimiter, to somewhere else, where you can use that data.

If you need help, post your serial output, so we can see what the GET request looks like.