Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By slumberjer
#47165 Hi i'm very new to this chip and arduino..

I've been looking for code so that my esp8266 can read value from url such as http://192.168.1.109:88/?value=1000 and use that value in the program. So far my code can read the returned url such as http://192.168.1.109:88/?buttonallon using the

Code: Select allString request = client.readStringUntil('\r');
request.indexOf("?buttonallon");
if (request.indexOf("?buttonallon") > 0 ) {
    digitalWrite(pin1, HIGH);
    value1 = HIGH;
  }


I need the browser to submit value (1000) to the esp so i can further process it.
Any help would be appreciated.
Thanks
User avatar
By slumberjer
#47206 well manage to solve this problem..not a beautiful solution but it works..I'm using substring and length to get the value. But this only work with single url post variable. If anyone had a good solution for this please do share. I very new to this programming world so bear with me.

But now there is another problem with my code. The variable that I use cannot be called within

Code: Select all 
void loop(){
 int len = (request.length()) - 9;
  String val = request.substring(15, len);
  String dur = request.substring(5, 14);
  int timer = val.toInt();
  client.flush();

  if (dur.compareTo("?duration") > 0) {
    Serial.print("DUR");
    Serial.println(timer);
  }
}


the "timer" value is zero when printed inside if statement. The value can only exist outside the if block. What give?
User avatar
By bbx10node
#47271 The ESP8266WebServer library is included with the Arduino ESP8266 board package. The example program HelloServer has code to parse multiple arguments.

When the HelloServer code is running on an ESP, connect to

http://esp8266.local/q?temp=100.0&humidity=32.1

The browser window should show something like this. This URL connects to a URL not handled by the web server because the handleNotFound() function conveniently prints out the arguments which confirms the library handles arguments correctly.

Code: Select allFile Not Found

URI: /q
Method: GET
Arguments: 2
 temp: 100.0
 humidity: 32.1


The following code in HelloServer.ino builds the response string.

Code: Select all  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);


You can use the methods server.args(), server.argName(), and server.arg() in handleroot() to process URLs like this.

[url]http://esp8266.local/?temp=100.0&humidity=32.1
[/url]
User avatar
By rahulmr
#48092
bbx10node wrote:The ESP8266WebServer library is included with the Arduino ESP8266 board package. The example program HelloServer has code to parse multiple arguments.

When the HelloServer code is running on an ESP, connect to

http://esp8266.local/q?temp=100.0&humidity=32.1

The browser window should show something like this. This URL connects to a URL not handled by the web server because the handleNotFound() function conveniently prints out the arguments which confirms the library handles arguments correctly.

Code: Select allFile Not Found

URI: /q
Method: GET
Arguments: 2
 temp: 100.0
 humidity: 32.1


The following code in HelloServer.ino builds the response string.

Code: Select all  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);


You can use the methods server.args(), server.argName(), and server.arg() in handleroot() to process URLs like this.

[url]http://esp8266.local/?temp=100.0&humidity=32.1
[/url]





Hi , Can you please check my post regarding the post values being accessed using the args. I could not get those values for some specific case. Please check this viewtopic.php?f=32&t=10167 and it would be helpful if you help me to sort that.

in short I have added the route as :
Code: Select allserver.on("/parseIFTTT", parseIFTTT);
void parseIFTTT() {

  String message;
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  Serial.println(message);
  server.send(200, "text/plain", "Success  " + message);
}


for the POST from postman client it is able to parse the args and getting the passed POST body.
But when I use the IFTTT to POST the webrequest , the data is not getting parsed and shown as blank.