Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Ervins
#92707 Hello!

I am trying to make app for my esp8266 project with MIT app inventor, but I have not been able to find info about how to do this on esp8266.
Is it possible to read undefined/partly defined arguments with server.on() function?

server.on("/Timer/...", startTimer);

I am trying to make a timer, but the duration is set in MIT app. Let's say the user sets the timer to 30 minutes. I would then calculate this in seconds and send it to esp8266 using webserver, like so..

https://www.linkpicture.com/q/Ekr%C4%81 ... 124041.png

I know I can define url to be sent and it can be used by esp8266.

server.on("/DisplayTime", clockDisplayTime);

void clockDisplayTime() {
getTimeDate();
displayTime();
intToByte();
displayDigits();
}

Also, I know there is server.onNotFound(); that potentially could be used to read values, but I am already using this to read RGB values sent by the app. Maybe there is a better way to do this as well?

server.onNotFound(setColor);

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

But is it possible to read url, that's partly defined?

I would like to start a function with server.on("/Timer/", startTimer);
and then read, what was sent after "Timer/" as value to use it in my program further.
User avatar
By Ervins
#92730 This can be closed, got the answer. Was not familiar with .arg function and this does the trick.

server.on("/StartTimer", [](){
if(server.hasArg("Time")){
String recTime = server.arg("Time");
timerTime = recTime.toInt();
Serial.println(timerTime);
}
startTimer();
});