Skip to content

Commit

Permalink
WebRTC connectivity fixes (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
npmenard committed Jan 9, 2024
1 parent ef16157 commit 02b78bd
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
fetch-depth: 2
- name: Build esp32 binary
run: |
bash -c 'export MICRO_RDK_USE_NVS=true && . "$IDF_PATH"/export.sh && . "$ESP_ROOT"/export-esp.sh && make build-esp32-with-cred-bin'
bash -c 'git config --global --add safe.directory && export MICRO_RDK_USE_NVS=true && . "$IDF_PATH"/export.sh && . "$ESP_ROOT"/export-esp.sh && make build-esp32-with-cred-bin'
cp examples/target/esp32-server-with-cred.bin micro-rdk-esp32-server.bin
- name: Upload release
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ esp-idf-svc = { version = "0.47.3", optional = true }
esp-idf-sys = { version = "0.33.7", features = ["binstart"], optional = true }
futures = "0.3.28"
futures-lite = "1.12.0"
h2 = "0.3.14"
h2 = "0.3.22"
hyper = { version="0.14.20", default-features = false, features = ["server","stream","http2"] }
lazy_static = "1.4.0"
local-ip-address = { version = "0.4.9", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 25 additions & 17 deletions examples/esp32-with-cred/esp32-server-with-cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ impl NvsStaticVars {
}
}

fn main() -> Result<(), ServerError> {
fn main() {
esp_idf_sys::link_patches();

esp_idf_svc::log::EspLogger::initialize_default();
let sys_loop_stack = EspSystemEventLoop::take()?;
let sys_loop_stack = EspSystemEventLoop::take().unwrap();

#[cfg(not(feature = "qemu"))]
let periph = Peripherals::take().map_err(|_| ServerError::PeripheralsError)?;
let periph = Peripherals::take()
.map_err(|_| ServerError::PeripheralsError)
.unwrap();

#[cfg(feature = "qemu")]
let repr = {
Expand All @@ -145,24 +147,30 @@ fn main() -> Result<(), ServerError> {

esp_idf_sys::esp!(unsafe {
esp_idf_sys::esp_vfs_eventfd_register(&esp_idf_sys::esp_vfs_eventfd_config_t { max_fds: 5 })
})?;
})
.unwrap();

info!("load vars from NVS...");
let nvs_vars = NvsStaticVars::new()?;
let nvs_vars = NvsStaticVars::new().unwrap();

#[cfg(feature = "qemu")]
let (ip, _block_eth) = {
use esp_idf_hal::prelude::Peripherals;
info!("creating eth object");
let mut eth = Box::new(esp_idf_svc::eth::EspEth::wrap(
esp_idf_svc::eth::EthDriver::new_openeth(
Peripherals::take()
.ok_or(ServerError::PeripheralsError)?
.mac,
sys_loop_stack.clone(),
)?,
)?);
let _ = eth_configure(&sys_loop_stack, &mut eth)?;
let mut eth = Box::new(
esp_idf_svc::eth::EspEth::wrap(
esp_idf_svc::eth::EthDriver::new_openeth(
Peripherals::take()
.ok_or(ServerError::PeripheralsError)
.unwrap()
.mac,
sys_loop_stack.clone(),
)
.unwrap(),
)
.unwrap(),
);
let _ = eth_configure(&sys_loop_stack, &mut eth).unwrap();
let ip = Ipv4Addr::new(10, 1, 12, 187);
(ip, eth)
};
Expand All @@ -183,8 +191,9 @@ fn main() -> Result<(), ServerError> {
sys_loop_stack,
&nvs_vars.wifi_ssid,
&nvs_vars.wifi_pwd,
)?;
(wifi.wifi().sta_netif().get_ip_info()?.ip, wifi)
)
.unwrap();
(wifi.wifi().sta_netif().get_ip_info().unwrap().ip, wifi)
};

let webrtc_certificate = WebRtcCertificate::new(
Expand All @@ -200,7 +209,6 @@ fn main() -> Result<(), ServerError> {
let cfg = AppClientConfig::new(nvs_vars.robot_secret, nvs_vars.robot_id, ip, "".to_owned());

serve_web(cfg, tls_cfg, repr, ip, webrtc_certificate);
Ok(())
}

#[cfg(feature = "qemu")]
Expand Down
15 changes: 8 additions & 7 deletions examples/esp32/esp32-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use {
esp_idf_sys::esp_wifi_set_ps,
};

fn main() -> anyhow::Result<()> {
fn main() {
esp_idf_sys::link_patches();

esp_idf_svc::log::EspLogger::initialize_default();
Expand All @@ -53,7 +53,8 @@ fn main() -> anyhow::Result<()> {
esp_idf_sys::esp_vfs_eventfd_register(&esp_idf_sys::esp_vfs_eventfd_config_t {
max_fds: 5,
})
})?;
})
.unwrap();
}

#[cfg(feature = "qemu")]
Expand All @@ -66,8 +67,9 @@ fn main() -> anyhow::Result<()> {
sys_loop_stack.clone(),
)
.unwrap(),
)?;
let (_, eth) = eth_configure(&sys_loop_stack, eth)?;
)
.unwrap();
let (_, eth) = eth_configure(&sys_loop_stack, eth).unwrap();
let ip = Ipv4Addr::new(10, 1, 12, 187);
(ip, eth)
};
Expand All @@ -81,8 +83,8 @@ fn main() -> anyhow::Result<()> {
#[allow(clippy::redundant_clone)]
#[cfg(not(feature = "qemu"))]
let (ip, _wifi) = {
let wifi = start_wifi(periph.modem, sys_loop_stack)?;
(wifi.wifi().sta_netif().get_ip_info()?.ip, wifi)
let wifi = start_wifi(periph.modem, sys_loop_stack).unwrap();
(wifi.wifi().sta_netif().get_ip_info().unwrap().ip, wifi)
};

let cfg = AppClientConfig::new(
Expand All @@ -104,7 +106,6 @@ fn main() -> anyhow::Result<()> {
};

serve_web(cfg, tls_cfg, repr, ip, webrtc_certificate);
Ok(())
}

#[cfg(feature = "qemu")]
Expand Down
Loading

0 comments on commit 02b78bd

Please sign in to comment.