Skip to content

Uri cannot be created from a flash string (WebServer.on calls) #4374

Closed
@TD-er

Description

@TD-er

Hardware:

Core Installation version: latest
IDE name: Platform.io
Computer OS: Windows 10

Description:

WebServer.on(...) function declaration now requires const Uri& uri.
However the Uri object cannot be constructed directly from a flash string.

Adding an extra constructor does seem to solve it, but I can't see why as the constructor of String also can handle a __FlashStringHelper* as argument

        Uri(const __FlashStringHelper* uri) : _uri(String(uri)) {}

N.B. this way of calling WebServer.on used to work just fine.

Sketch: (leave the backquotes for code formatting)

//Change the code below by your sketch
web_server.on(F("/"),                 handle_root);

Compiler output

C:/GitHub/TD-er/ESPEasy/src/WebServer.ino: In function 'void WebServerInit()':
C:/GitHub/TD-er/ESPEasy/src/WebServer.ino:180:36: error: no matching function for call to 'WebServer::on(const __FlashStringHelper*, void (&)())'
   web_server.on(F("/"),                 handle_root);
                                    ^
In file included from src\ESPEasy_fdwdecl.h:25:0,
                 from src\ESPEasy-Globals.h:28,
                 from C:/GitHub/TD-er/ESPEasy/src/ESPEasy.ino:92:
C:/users/gijsn/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:88:8: note: candidate: void WebServer::on(const Uri&, WebServer::THandlerFunction)
   void on(const Uri &uri, THandlerFunction handler);
        ^
C:/users/gijsn/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:88:8: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const Uri&'
C:/users/gijsn/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:89:8: note: candidate: void WebServer::on(const Uri&, HTTPMethod, WebServer::THandlerFunction)
   void on(const Uri &uri, HTTPMethod method, THandlerFunction fn);
        ^
C:/users/gijsn/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:89:8: note:   candidate expects 3 arguments, 2 provided
C:/users/gijsn/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:90:8: note: candidate: void WebServer::on(const Uri&, HTTPMethod, WebServer::THandlerFunction, WebServer::THandlerFunction)
   void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
        ^
C:/users/gijsn/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:90:8: note:   candidate expects 4 arguments, 2 provided
*** [.pio\build\custom_ESP32_4M316k_ETH\src\ESPEasy.ino.cpp.o] Error 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions