|
|
@ -19,6 +19,7 @@ typedef struct { |
|
|
|
api_put_callback_f putFn = NULL; |
|
|
|
} web_api_t; |
|
|
|
std::vector<web_api_t> _apis; |
|
|
|
bool _api_restful = API_RESTFUL; |
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
@ -31,8 +32,14 @@ void _apiWebSocketOnSend(JsonObject& root) { |
|
|
|
root["apiEnabled"] = getSetting("apiEnabled", API_ENABLED).toInt() == 1; |
|
|
|
root["apiKey"] = getSetting("apiKey"); |
|
|
|
root["apiRealTime"] = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1; |
|
|
|
root["apiRestFul"] = _api_restful; |
|
|
|
} |
|
|
|
|
|
|
|
void _apiConfigure() { |
|
|
|
_api_restful = getSetting("apiRestFul", API_RESTFUL).toInt() == 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// API
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
@ -158,9 +165,11 @@ bool _apiRequestCallback(AsyncWebServerRequest *request) { |
|
|
|
|
|
|
|
// Check if its a PUT
|
|
|
|
if (api.putFn != NULL) { |
|
|
|
if (request->hasParam("value", request->method() == HTTP_PUT)) { |
|
|
|
AsyncWebParameter* p = request->getParam("value", request->method() == HTTP_PUT); |
|
|
|
(api.putFn)((p->value()).c_str()); |
|
|
|
if (!_api_restful || (request->method() == HTTP_PUT)) { |
|
|
|
if (request->hasParam("value", request->method() == HTTP_PUT)) { |
|
|
|
AsyncWebParameter* p = request->getParam("value", request->method() == HTTP_PUT); |
|
|
|
(api.putFn)((p->value()).c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -215,6 +224,7 @@ void apiSetup() { |
|
|
|
wsOnSendRegister(_apiWebSocketOnSend); |
|
|
|
wsOnReceiveRegister(_apiWebSocketOnReceive); |
|
|
|
webRequestRegister(_apiRequestCallback); |
|
|
|
espurnaRegisterReload(_apiConfigure); |
|
|
|
} |
|
|
|
|
|
|
|
#endif // API_SUPPORT
|