logo elektroda
logo elektroda
X
logo elektroda

[ESP07][Arduino][ESPAsyncWebServer] - I can't move functions to their own classes

sq9etc 927 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18825738
    sq9etc
    Level 12  
    When I have all the variables and functions relating to the server in the main.c file it is fine. The program compiles and runs.
    Code: C / C++
    Log in, to see the code
    .

    When the variables t , h and index_html[] and functions processor and initWebServer I will move to my own class, then the program stops compiling.
    The following errors appear in the method WebServer::init :
    Code: Bash
    Log in, to see the code
    .

    The code looks as follows:
    Code: C / C++
    Log in, to see the code
    .

    Code: C / C++
    Log in, to see the code
    .

    Code: C / C++
    Log in, to see the code
    .

    What am I doing wrong?
  • ADVERTISEMENT
  • #2 18825915
    Anonymous
    Level 1  
  • #3 18827162
    sq9etc
    Level 12  
    khoam wrote:
    The second and third errors are of the same type. You should use send() instead of send_P():
    .
    Then why does it work send_P() in the non-object version?
  • #4 18827327
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #5 18828565
    sq9etc
    Level 12  
    For the first error I converted the function processor to static according to your suggestion. Now I have 2 errors that it does not know t and h .
    For the other two errors I changed the function calls send_P() to send() , but I still get the error 'this' was not captured for this lambda function .
  • #6 18828578
    Anonymous
    Level 1  
  • #7 18828591
    sq9etc
    Level 12  
    Code: C / C++
    Log in, to see the code
    .

    Code: Bash
    Log in, to see the code
    .
  • ADVERTISEMENT
  • Helpful post
    #8 18828637
    Anonymous
    Level 1  
  • #9 18828650
    sq9etc
    Level 12  
    Thanks, that helped.
    I still don't know what to do to make the static function processor see the fields t and h .
    Code: Bash
    Log in, to see the code
    .
  • #10 18828669
    Anonymous
    Level 1  
  • #11 18837265
    sq9etc
    Level 12  
    I did as recommended. Now there is this error:
    Code: Bash
    Log in, to see the code
    .

    i.e. again can't match method String WebServer::processor(const String& var) as parameter of function send_P .
  • Helpful post
    #12 18837431
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #13 18838169
    sq9etc
    Level 12  
    Thanks, you are great. Now it compiles and even works:) .

Topic summary

The discussion revolves around issues faced when attempting to refactor an Arduino project using the ESPAsyncWebServer library by moving functions into their own classes. The user initially encounters compilation errors related to function type mismatches and variable scope, particularly with the static function `processor` not being able to access instance variables `t` and `h`. Solutions proposed include making the `processor` function non-static and using lambda functions to capture the necessary variables. Ultimately, the user successfully resolves the issues and achieves a working implementation.
Summary generated by the language model.
ADVERTISEMENT