Page 1 of 1

ESP8266 WebServer server.on() undefined arguments

PostPosted: Mon Oct 25, 2021 7:04 am
by Ervins

I am building a mobile app (MIT app inventor) for my esp8266 project and now I am working on timer function.
User sets wanted delay for the timer on the app, app converts it to seconds and sends it to esp8266 like so.


I am wondering, is it possible for esp8266, using server.on("/StartTimer/...", startTimer); to read "/StartTimer/" part, run the function, and then figure out, what values were sent after "/StartTimer/".

I know server.onNotFound(); could be used to read any url, but I am kinda already using it to get color codes like so...

void setColor() {
String RGBColors = server.uri();
String RGBColorR = RGBColors.substring(RGBColors.indexOf("R"), RGBColors.indexOf("G"));
RGBColorRed = RGBColorR.toInt();
String RGBColorG = RGBColors.substring(RGBColors.indexOf("G"), RGBColors.indexOf("B"));
RGBColorGreen = RGBColorG.toInt();
String RGBColorB = RGBColors.substring(RGBColors.indexOf("B"));
RGBColorBlue = RGBColorB.toInt();
analogWrite(RGBLedR, resolution - RGBColorRed);
analogWrite(RGBLedG, resolution - RGBColorGreen);
analogWrite(RGBLedB, resolution - RGBColorBlue);
displayMode = 0;

I have a feeling that this is not the best way, but I can't find info on this topic.

Re: ESP8266 WebServer server.on() undefined arguments

PostPosted: Wed Oct 27, 2021 12:09 am
by JurajA

Re: ESP8266 WebServer server.on() undefined arguments

PostPosted: Wed Oct 27, 2021 8:21 am
by Ervins
Thanks JurajA!

Did some research and got some basic knowledge of arguments.

server.on("/StartTimer", [](){
String recTime = server.arg("Time");
timerTime = recTime.toInt();

Works like a charm, thanks again!