esp32 cam. How to change Port and URL für stream?

Hi,

I am working on an alternative firmware for esp32 cam in elegoo smartc ar v4. It has an esp32 cam module which streams the camera to their eleRobot app. I want to reimplement the software to be able to add encryption for the esp32's wifi.

I played with the esp32 cameraWebServer example. The stream is available at http://<IP_OF_CAM>:81/stream. I need to change it to http://<IP_OF_CAM>:80/Test.

I haven't found the spot in the source of the example yet. Can you please help how to change it?
Thanks a lot!

Can you post the source code or is it too long?

Code is quite long and loads multiple files and a quite big library. Its the named example sketch, so I thougt I don't need to post it. It is in esp32 addtions. I am using Version 1.0.3.

I am a bit further and tracked the port assignment down to file app_httpd.cpp in function void startCameraServer().

void startCameraServer(){
    httpd_config_t config = HTTPD_DEFAULT_CONFIG();

    httpd_uri_t index_uri = {
        .uri       = "/",
        .method    = HTTP_GET,
        .handler   = index_handler,
        .user_ctx  = NULL
    };

    httpd_uri_t status_uri = {
        .uri       = "/status",
        .method    = HTTP_GET,
        .handler   = status_handler,
        .user_ctx  = NULL
    };

    httpd_uri_t cmd_uri = {
        .uri       = "/control",
        .method    = HTTP_GET,
        .handler   = cmd_handler,
        .user_ctx  = NULL
    };

    httpd_uri_t capture_uri = {
        .uri       = "/capture",
        .method    = HTTP_GET,
        .handler   = capture_handler,
        .user_ctx  = NULL
    };

   httpd_uri_t stream_uri = {
        .uri       = "/Test",
        .method    = HTTP_GET,
        .handler   = stream_handler,
        .user_ctx  = NULL
    };


    ra_filter_init(&ra_filter, 20);
    
    mtmn_config.type = FAST;
    mtmn_config.min_face = 80;
    mtmn_config.pyramid = 0.707;
    mtmn_config.pyramid_times = 4;
    mtmn_config.p_threshold.score = 0.6;
    mtmn_config.p_threshold.nms = 0.7;
    mtmn_config.p_threshold.candidate_number = 20;
    mtmn_config.r_threshold.score = 0.7;
    mtmn_config.r_threshold.nms = 0.7;
    mtmn_config.r_threshold.candidate_number = 10;
    mtmn_config.o_threshold.score = 0.7;
    mtmn_config.o_threshold.nms = 0.7;
    mtmn_config.o_threshold.candidate_number = 1;
    
    face_id_init(&id_list, FACE_ID_SAVE_NUMBER, ENROLL_CONFIRM_TIMES);
    
    config.server_port = 8080;
    Serial.printf("Starting web server on port: '%d'\n", config.server_port);
    if (httpd_start(&camera_httpd, &config) == ESP_OK) {
        httpd_register_uri_handler(camera_httpd, &index_uri);
        httpd_register_uri_handler(camera_httpd, &cmd_uri);
        httpd_register_uri_handler(camera_httpd, &status_uri);
        httpd_register_uri_handler(camera_httpd, &capture_uri);
//        httpd_register_uri_handler(stream_httpd, &stream_uri);


    }

    config.server_port = 80;
    config.ctrl_port += 1;
    Serial.printf("Starting stream server on port: '%d'\n", config.server_port);
    if (httpd_start(&stream_httpd, &config) == ESP_OK) {
        httpd_register_uri_handler(stream_httpd, &stream_uri);
    }
}

I was able to change the path here in .uri line:

  httpd_uri_t stream_uri = {
        .uri       = "/Test",
        .method    = HTTP_GET,
        .handler   = stream_handler,
        .user_ctx  = NULL
    };

Also I changed the server ports for the default server to 8080 and the stream server to 80 by setting config.server_port before calling httpd_start. So this seems to work for me at first glance, but there is one thing I don't understand. Why does it not work to just register the stream_uri hanlder within the first server instance? Why do I need a specific server instance with additional port?

This here does not work. Access to /Test gives me HTTP 404 URI does not exist.

   config.server_port = 80;
    Serial.printf("Starting web server on port: '%d'\n", config.server_port);
    if (httpd_start(&camera_httpd, &config) == ESP_OK) {
        httpd_register_uri_handler(camera_httpd, &index_uri);
        httpd_register_uri_handler(camera_httpd, &cmd_uri);
        httpd_register_uri_handler(camera_httpd, &status_uri);
        httpd_register_uri_handler(camera_httpd, &capture_uri);
        httpd_register_uri_handler(stream_httpd, &stream_uri);
    }

(registered &stream_uri at last)

Thanks a lot

Hi,
Could you please give some more details on how you started the web server example? I'm still a little confused about what to expect from the camera module, I'm not sure if it's possible to change the code running on the ESP32.

I'm quite new to this, so help would be appreciated.

butch:
Also I changed the server ports for the default server to 8080 and the stream server to 80 by setting config.server_port before calling httpd_start. So this seems to work for me at first glance, but there is one thing I don't understand. Why does it not work to just register the stream_uri hanlder within the first server instance? Why do I need a specific server instance with additional port?

It does work. I've just moved the stream server from port 81 to 80 so I can use the control panel with ngrok. After you registered the stream URL with:

httpd_register_uri_handler(stream_httpd, &stream_uri);

then you have to comment out:

    /*
    config.server_port = 80;
    config.ctrl_port += 1;
    Serial.printf("Starting stream server on port: '%d'\n", config.server_port);
    if (httpd_start(&stream_httpd, &config) == ESP_OK) {
        httpd_register_uri_handler(stream_httpd, &stream_uri);
    }
    */

and then you can access the stream server with:

xxx.xxx.xxx.xxx/Test

If you want to after moving the stream server to port 80 still use the control panel you have to edit the HTML served by the ESP32 which is in:

const uint8_t index_ov2640_html_gz[] = { ... }

inside file camera_index.h

Use Cyberchef to decode the byte array into HTML, recipe =

From_Hex('Auto')
Gunzip()

change the line:

var streamUrl = baseHost + ':81'

to

var streamUrl = baseHost

and convert the HTML back into the byte array, recipe =

Gzip('Dynamic Huffman Coding','','',false)
To_Hex('0x with comma',16)

The last thing is to count the bytes end to edit:

#define index_ov2640_html_gz_len

and now everything (control panel + still image + stream) works on port 80.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.