• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Esp32 problem compiling AsyncWebServer server.on

Q&A Forum › Category: ESP32 › Esp32 problem compiling AsyncWebServer server.on
0 Vote Up Vote Down
Barry asked 4 years ago

I have an error when compiling. No clue on where the type conversion is occurring.
I don’t see a typo. Using Arduino IDE 1.8.13
Any help would be much appreciated.
BB

CODE

server.on(“/get”, HTTP_GET, [] (AsyncWebServerRequest *request) {    <<<<<<< this line has error
int paramsNr = request->params;

 

ERROR MSG
Arduino: 1.8.13 (Windows 10), Board: “ESP32 Dev Module, Enabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 115200, None”
C:\Users\iabar\Documents\ESP32\4_WayServer_015a\4_WayServer_015a.ino: In lambda function:
4_WayServer_015a:328:29:

UPDATE – just determined the error is a related to “int paramsNr” type conversion.

 

error: cannot convert ‘AsyncWebServerRequest::params’ from type ‘size_t (AsyncWebServerRequest::)() const {aka unsigned int (AsyncWebServerRequest::)() const}’ to type ‘int’
int paramsNr = request->params;

Question Tags: Asyncwebserver
6 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Barry.
I’m not sure, but I think you need to get the parameter as a String. Also, I think it is better to declare the variable outside the server.on().
Like this, for example:

String paramsNr;
int paramsNrInt;
server.on(“/get”, HTTP_GET, [] (AsyncWebServerRequest *request) {
paramsNr = request->params;
paramsNrInt =  paramsNr.toIn();

I haven’t tried it. Let me know if this works.
Regards,
Sara

0 Vote Up Vote Down
Barry answered 4 years ago

//Global Vars
String paramsNr;
 
server.on(“/get”, HTTP_GET, [] (AsyncWebServerRequest *request) {
paramsNr = request->params;
^^^ “This generates error “invalid use of non-static member function”

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Can you share your complete code with me?
Otherwise, it is very difficult to debug.
To share your code use a link to pastebin, github, google drive, or others.
Regards,
Sara

0 Vote Up Vote Down
Barry answered 4 years ago

Thank you Sara. I continue to make progress.
I’m having trouble with the server.on(“/get”…
Possibly the “/get” thinks that the get is on the root (index.html) page. In my case is it NOT. I have a page    which is “/wifi_config.html”
Tried putting the full URL in front of the /get but this IF statement keeps failing. Also tried removing the ‘/’ from the front of “get” and no luck with that either.
All of the online examples are working from root (index.html) and I can’t find a good detailed explanation of what should be included.
 
[code]
server.on(“/get”, HTTP_GET, [] (AsyncWebServerRequest *request) {
                 ^^^^  THIS IS THE PROBLEM

String inputMessage;
String inputParam;
Serial.println(“in server.on /get”);
if (request->hasParam(htmlssid)) {
inputMessage = request->getParam(htmlssid)->value();
inputParam = htmlssid;
Serial.print(“Value: “);
Serial.println(inputParam);
Serial.println();
Serial.println(inputMessage);
[/code]

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Can you show me the form in your HTML file? So that I can test the example and try to see what’s going on.
Thanks.
Regards,
Sara

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

I think you may be missing the way server.on() works. Yours is waiting for a URL of the form “<ESP_IP>/get?<htmlssid>=<value>”. eg. 192.168.1.22/get?myssid=helloworld. So, on your “/wifi_config.html” page you would have a link to that URL.
 
I hope I explained that OK?
 
Reading through the ESPAsyncWebServer documentation you see that request->params is not an int, it’s a function – request->params() and the return from that function is an int (the number of parameters sent).

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.