|
|
@@ -676,9 +676,42 @@ esp_err_t GpioHandler::handleHttpRequest(httpd_req_t *req)
|
|
|
std::lock_guard<std::recursive_mutex> lock(_mapMutex);
|
|
|
ESP_LOGD(TAG, "handleHttpRequest");
|
|
|
|
|
|
+ char _query[200];
|
|
|
+ if (httpd_req_get_url_query_str(req, _query, sizeof(_query)) == ESP_OK) {
|
|
|
+ char capabilitiesRequest[8] = {};
|
|
|
+ if (httpd_query_key_value(_query, "capabilities", capabilitiesRequest,
|
|
|
+ sizeof(capabilitiesRequest)) == ESP_OK &&
|
|
|
+ strcmp(capabilitiesRequest, "1") == 0) {
|
|
|
+ const GpioBoardProfile *profile = gpioGetBoardProfile();
|
|
|
+ if (profile == NULL || !gpioBoardProfileIsValid()) {
|
|
|
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR,
|
|
|
+ "Invalid GPIO board profile");
|
|
|
+ return ESP_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string response = "{\\"profile\\":\\"";
|
|
|
+ response += profile->name;
|
|
|
+ response += "\\",\\"maxChannels\\":";
|
|
|
+ response += std::to_string(profile->maxUserChannels);
|
|
|
+ response += ",\\"pins\\":[";
|
|
|
+ for (size_t i = 0; i < profile->userPinCount; ++i) {
|
|
|
+ if (i > 0U) response += ",";
|
|
|
+ response += "{\\"gpio\\":";
|
|
|
+ response += std::to_string(static_cast<int>(profile->userPins[i].gpio));
|
|
|
+ response += ",\\"capabilities\\":";
|
|
|
+ response += std::to_string(profile->userPins[i].capabilities);
|
|
|
+ response += "}";
|
|
|
+ }
|
|
|
+ response += "]}";
|
|
|
+ httpd_resp_set_type(req, "application/json");
|
|
|
+ httpd_resp_set_hdr(req, "Cache-Control", "no-store");
|
|
|
+ httpd_resp_send(req, response.c_str(), response.length());
|
|
|
+ return ESP_OK;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (gpioMap == NULL) {
|
|
|
- std::string resp_str = "GPIO handler not initialized";
|
|
|
- httpd_resp_send(req, resp_str.c_str(), resp_str.length());
|
|
|
+ httpd_resp_sendstr(req, "GPIO handler not initialized");
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
@@ -687,7 +720,6 @@ esp_err_t GpioHandler::handleHttpRequest(httpd_req_t *req)
|
|
|
#endif
|
|
|
|
|
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_switch_GPIO");
|
|
|
- char _query[200];
|
|
|
char _valueGPIO[30];
|
|
|
char _valueStatus[30];
|
|
|
std::string gpio, status;
|