esp_http_handler.cpp
static const httpd_uri_t valueHandler = {
.uri = "/api/value",
.method = HTTP_GET,
.handler = [](httpd_req_t *req) {
httpd_resp_set_type(req, "application/json");
// create json docuemnt
DynamicJsonDocument json(1024);
json["value"] = 1.0;
// Serialize JSON to string
std::string buf;
serializeJson(json, buf);
// Send response
httpd_resp_send(req, buf.c_str(), buf.length());
return ESP_OK;
}
};Para adicionar o ArduinoJson ao PlatformIO, adicione o seguinte lib_deps ao platformio.ini:
platformio.ini
lib_deps =
ArduinoJSON@6.17.2
Check out similar posts by category:
Arduino ESP8266/ESP32
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow