Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a wildcard in ESP8266WebServer

I want to send all paths that start with "/robot" to a certain handler using ESP8266WebServer.h. I tried a few variations:

server.on ( "/robot", handleDirection );
server.on ( "/robot/", handleDirection );
server.on ( "/robot/*", handleDirection );

But in each case, it only listens for the exact path (including the * for that one).

Does this library just not support wildcard paths? Or am I missing how to do it?

like image 791
Sam Jones Avatar asked Mar 05 '16 16:03

Sam Jones


1 Answers

This is very easy in OO way

class MyHandler : public RequestHandler {

  bool canHandle(HTTPMethod method, String uri) {
    return uri.startsWith( "/robot" );
  }

  bool handle(ESP8266WebServer& server, HTTPMethod requestMethod, String requestUri) {    
    doRobot( requestUri );
    server.send(200, "text/plain", "Yes!!");
    return true;
  }

} myHandler;

...
  server.addHandler( &myHandler );
...
like image 194
Daniel De León Avatar answered Jan 04 '23 06:01

Daniel De León