Closed redemption95 closed 5 years ago
static esp_err_t ws_ping_handler(httpd_req_t *req)
{
uint8_t buf[128] = { 0 };
httpd_ws_pkt_t ws_pkt;
memset(&ws_pkt, 0, sizeof(httpd_ws_pkt_t));
ws_pkt.payload = buf;
esp_err_t ret = httpd_ws_recv_pkt(req, &ws_pkt, 128, 60000);
ESP_LOGI(TAG, "Got packet with message: %s", ws_pkt.payload);
ret = ret ? : httpd_ws_send_pkt(req, &ws_pkt);
return ret;
}
static const httpd_uri_t ws = {
.uri = "/ws",
.method = HTTP_GET,
.handler = ws_ping_handler,
.user_ctx = NULL,
.is_websocket = true
};
static httpd_handle_t start_webserver(void)
{
httpd_handle_t server = NULL;
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
// Start the httpd server
ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
if (httpd_start(&server, &config) == ESP_OK) {
// Set URI handlers
ESP_LOGI(TAG, "Registering URI handlers");
// ...some other HTTP endpoint handlers also add at here
httpd_register_uri_handler(server, &ws);
return server;
}
ESP_LOGI(TAG, "Error starting server!");
return NULL;
}
----------------------------- Delete below -----------------------------
If your issue is a general question, starts similar to "How do I..", or is related to 3rd party development kits/libs, please discuss this on our community forum at esp32.com instead.
INSTRUCTIONS
Before submitting a new issue, please follow the checklist and try to find the answer.
If the issue cannot be solved after the steps before, please follow these instructions so we can get the needed information to help you in a quick and effective fashion.
----------------------------- Delete above -----------------------------
Environment
git describe --tags
to find it): // v3.2-dev-1148-g96cd3b75cxtensa-esp32-elf-gcc --version
to find it): // 1.22.0-80-g6c4433aProblem Description
//Detailed problem description goes here.
Expected Behavior
Actual Behavior
Steps to repropduce
// It helps if you attach a picture of your setup/wiring here.
Code to reproduce this issue
// If your code is longer than 30 lines, GIST is preferred.
Debug Logs
Other items if possible
build
folder (note this may contain all the code details and symbols of your project.)