}// 发送HTTP响应httpd_resp_set_type(req, HTTPD_TYPE_TEXT);httpd_resp_send(req,"Received data: ",-1);httpd_resp_send_chunk(req, buf, req->content_len);httpd_resp_send_chunk(req,NULL,0);returnESP_OK; } 5. 处理web socket连接 除了支持HTTP请求外,ESP-IDF的Web服务器还支持WebSocket连接。
httpd_resp_set_type(req, "application/json"); httpd_resp_set_hdr(req, "Connection", "keep-alive"); httpd_resp_set_hdr(req, "WWW-Authenticate", "Basic realm=\"Hello\""); httpd_resp_send(req, NULL, 0); } else { ESP_LOGI(TAG, "Authenticated!"); char *basic_auth_resp = NULL;...
httpd_resp_set_hdr(req, "Custom-Header-2", "Custom-Value-2"); /* Send response with custom headers and body set as the * string passed in user context*/ const char* resp_str = (const char*) req->user_ctx; httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN); /* After send...
res=httpd_resp_send_chunk(req, (const char*)part_buf, hlen); } if(res==ESP_OK){ res=httpd_resp_send_chunk(req, (const char*)_jpg_buf, _jpg_buf_len); } if(res==ESP_OK){ res=httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); } if(fb){ esp_camera_f...
{ /* 如果发生超时,重试接收 */ continue; } return ESP_FAIL; } /* 发回相同的数据 */ httpd_resp_send_chunk(req, buf, ret); remaining -= ret; esp_err_t ret = httpd_query_key_value(buf, "ssid", wifi_name, sizeof(wifi_name)); if (ret == ESP_OK) { char str[32]; memcpy(...
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len); } if(res == ESP_OK){ res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); } if(fb){ esp_camera_fb_return(fb); fb = NULL; ...
res=httpd_resp_send_chunk(req,(constchar*)_jpg_buf,_jpg_buf_len); } if(res==ESP_OK){ res=httpd_resp_send_chunk(req,_STREAM_BOUNDARY,strlen(_STREAM_BOUNDARY)); } if(fb){ esp_camera_fb_return(fb); fb=NULL; _jpg_buf=NULL; ...
if (ret == HTTPD_SOCK_ERR_TIMEOUT) { /* Retry receiving if timeout occurred */ continue; } return ESP_FAIL; } /* Send back the same data */ httpd_resp_send_chunk(req, buf, ret); remaining -= ret; /* Log data received */ ESP_LOGI(TAG, ...
res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen); ``` 首先时利用Snprintf函数格式化字符串,定义长度为64,将包含有图像长度的_STREAM_PART字符转复制到地址part_buf上。相当于这个字符转就是说明图像的类型和长度。 [C 库函数 – snprintf() | 菜鸟教程 (runoob.com)](C 库函数 - snp...
res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen); } if(res == ESP_OK){ res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len); } if(res == ESP_OK){ res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); ...