1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 22:43:07 +01:00

add registerRequestHandler to the API with examples

This commit is contained in:
andreas
2024-11-14 18:15:12 +01:00
parent 506dd7ea9f
commit 538f643fbf
9 changed files with 133 additions and 4 deletions

View File

@@ -348,6 +348,8 @@ public:
}
return xdrMappings.addFixedMapping(mapping);
}
virtual void registerRequestHandler(const String &url,HandlerFunction handler){
}
virtual void addCapability(const String &name, const String &value){}
virtual bool addUserTask(GwUserTaskFunction task,const String Name, int stackSize=2000){
return false;
@@ -768,6 +770,7 @@ void loopFunction(void *){
//delay(1);
}
}
const String USERPREFIX="/api/user/";
void setup() {
mainLock=xSemaphoreCreateMutex();
uint8_t chipid[6];
@@ -845,7 +848,12 @@ void setup() {
snprintf(buffer,29,"%g",value);
buffer[29]=0;
request->send(200,"text/plain",buffer);
});
});
webserver.registerHandler((USERPREFIX+"*").c_str(),[&USERPREFIX](AsyncWebServerRequest *req){
String turl=req->url().substring(USERPREFIX.length());
logger.logDebug(GwLog::DEBUG,"user web request for %s",turl.c_str());
userCodeHandler.handleWebRequest(turl,req);
});
webserver.begin();
xdrMappings.begin();