esp-rs / esp-idf-svc

Type-Safe Rust Wrappers for various ESP-IDF services (WiFi, Network, Httpd, Logging, etc.)
https://docs.esp-rs.org/esp-idf-svc/
Apache License 2.0
332 stars 183 forks source link

EspHttpServer https server error #497

Closed iyfedorov closed 1 month ago

iyfedorov commented 1 month ago

Hello! I tried make http server with tls by adding certs in configuration in my code

let settings = esp_idf_svc::http::server::Configuration {
        #[cfg(esp_idf_esp_https_server_enable)]
        server_certificate: Some(X509::pem(
            CStr::from_bytes_with_nul(certs::SERVER_CERT.as_bytes()).unwrap(),
        )),
        #[cfg(esp_idf_esp_https_server_enable)]
        private_key: Some(X509::pem(
            CStr::from_bytes_with_nul(certs::SERVER_KEY.as_bytes()).unwrap(),
        )),
        ..Default::default()
    };

and enabled flag esp_idf_esp_https_server_enable in config.toml

rustflags ="--cfg espidf_time64 --cfg esp_idf_esp_https_server_enable"

but when i call cargo build i got next errors:

error[E0412]: cannot find type `httpd_ssl_config_t` in this scope
     --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:195:39
      |
195   | impl From<&Configuration> for Newtype<httpd_ssl_config_t> {
      |                                       ^^^^^^^^^^^^^^^^^^
      |
     ::: /tmp/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-a0836d99356d9db3/out/bindings.rs:46456:1
      |
46456 | pub type httpd_config_t = httpd_config;
      | ----------------------- similarly named type alias `httpd_config_t` defined here
      |
help: a type alias with a similar name exists
      |
195   | impl From<&Configuration> for Newtype<httpd_config_t> {
      |                                       ~~~~~~~~~~~~~~
help: you might be missing a type parameter
      |
195   | impl<httpd_ssl_config_t> From<&Configuration> for Newtype<httpd_ssl_config_t> {
      |     ++++++++++++++++++++

error[E0425]: cannot find value `httpd_ssl_transport_mode_t_HTTPD_SSL_TRANSPORT_SECURE` in this scope
   --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:200:35
    |
200 |             (Some(_), Some(_)) => httpd_ssl_transport_mode_t_HTTPD_SSL_TRANSPORT_SECURE,
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `httpd_ssl_transport_mode_t_HTTPD_SSL_TRANSPORT_INSECURE` in this scope
   --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:203:17
    |
203 |                 httpd_ssl_transport_mode_t_HTTPD_SSL_TRANSPORT_INSECURE
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0422]: cannot find struct, variant or union type `httpd_ssl_config_t` in this scope
     --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:209:14
      |
209   |         Self(httpd_ssl_config_t {
      |              ^^^^^^^^^^^^^^^^^^ help: a type alias with a similar name exists: `httpd_config_t`
      |
     ::: /tmp/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-a0836d99356d9db3/out/bindings.rs:46456:1
      |
46456 | pub type httpd_config_t = httpd_config;
      | ----------------------- similarly named type alias `httpd_config_t` defined here

error[E0412]: cannot find type `httpd_ssl_config_t` in this scope
     --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:337:37
      |
337   |             let mut config: Newtype<httpd_ssl_config_t> = conf.into();
      |                                     ^^^^^^^^^^^^^^^^^^
      |
     ::: /tmp/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-a0836d99356d9db3/out/bindings.rs:46456:1
      |
46456 | pub type httpd_config_t = httpd_config;
      | ----------------------- similarly named type alias `httpd_config_t` defined here
      |
help: a type alias with a similar name exists
      |
337   |             let mut config: Newtype<httpd_config_t> = conf.into();
      |                                     ~~~~~~~~~~~~~~
help: you might be missing a type parameter
      |
296   | impl<'a, httpd_ssl_config_t> EspHttpServer<'a> {
      |        ++++++++++++++++++++

error[E0425]: cannot find function `httpd_ssl_stop` in module `crate::sys`
     --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:421:39
      |
421   |             esp!(unsafe { crate::sys::httpd_ssl_stop(self.sd) })?;
      |                                       ^^^^^^^^^^^^^^ help: a function with a similar name exists: `httpd_stop`
      |
     ::: /tmp/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-a0836d99356d9db3/out/bindings.rs:46463:5
      |
46463 |     pub fn httpd_stop(handle: httpd_handle_t) -> esp_err_t;
      |     ------------------------------------------------------ similarly named function `httpd_stop` defined here

error[E0425]: cannot find function `httpd_ssl_start` in this scope
     --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:361:31
      |
361   |                 esp!(unsafe { httpd_ssl_start(handle_ref, &mut config.0) })?;
      |                               ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `httpd_start`
      |
     ::: /tmp/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-a0836d99356d9db3/out/bindings.rs:46459:5
      |
46459 |     pub fn httpd_start(handle: *mut httpd_handle_t, config: *const httpd_config_t) -> esp_err_t;
      |     ------------------------------------------------------------------------------------------- similarly named function `httpd_start` defined here

error[E0425]: cannot find function `httpd_ssl_start` in this scope
     --> /home/esp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.49.1/src/http/server.rs:363:31
      |
363   |                 esp!(unsafe { httpd_ssl_start(handle_ref, &mut config.0) })?;
      |                               ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `httpd_start`
      |
     ::: /tmp/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-a0836d99356d9db3/out/bindings.rs:46459:5
      |
46459 |     pub fn httpd_start(handle: *mut httpd_handle_t, config: *const httpd_config_t) -> esp_err_t;
      |     ------------------------------------------------------------------------------------------- similarly named function `httpd_start` defined here

What i do wrong? (simple http server was successfullty started up). Thx

iyfedorov commented 1 month ago

Versions:

[dependencies]
log = { version = "0.4", default-features = false }
esp-idf-svc = "0.49.0"
esp-idf-sys = "=0.35.0"
anyhow = "=1.0.89"
embedded-svc = "=0.28.0"
shtcx        = "=1.0.0"
toml-cfg     = "=0.2.0"
ivmarkov commented 1 month ago

Don't enable any esp_idf_ flag explicitly yourself. Enable the HTTPS server by following the ESP IDF documentation and putting the relevant CONFIG_ entries in your sdkconfig.defaults.

This would take care of everything, including the generation of the relevant Rust cfgs for you.