-->
Page 1 of 1

Two ?'s re: ESP8266WebServer & structs

PostPosted: Sat Jan 09, 2016 12:45 pm
by damage31
I'm new to C/C++, so please bear with me. I've been able to mashup a mostly working web server sketch, with 2 notable exceptions - and those are my questions:

Question#1: Wondering if anyone knows if its possible to have the usual
Code: Select allserver.on("/", someMethodName);

call a method that needs parameters, and if so, how? I haven't seen any examples anywhere, and don't know what this should look like.

While the following won't/doesn't work, I have no idea how to proceed further - can anyone shed some light on what to google or learn about?
Code: Select allserver.on("/", myMethodNameThatNeedsAParameter(myStructIWantedToPass));


Question #2 is kind of related to the above, and is more about structs - how would I define a global struct that I could pass around so it can be modified in the methods/functions that get called in this type of scenario? Is this the way to define the struct? The code below is quick pseudocode - I'm just trying to get my thoughts across-

Code: Select all#include <ESP8266WebServer.h>

typedef struct Setting {
      bool configured;
};

Setting someGlobalSetting; //is this how to do this here? this would be global scope for the whole sketch?

void setup(){
    someGlobalSetting.configured = true;
    //other misc code...
}

void loop(){
if (someGlobalSetting.configured){
    ...do something useful
}

Re: Two ?'s re: ESP8266WebServer & structs

PostPosted: Sat Jan 09, 2016 5:37 pm
by eduperez
#1
No, there is no such call to "server.on"; and by the way, it would have to be something along the lines of:
Code: Select allserver.on("/", myMethodNameThatNeedsAParameter, myStructIWantedToPass);

I guess you must use an intermediate function that does not receive any parameter and calls your other function.

#2
That code seems correct, it is how I would do it.