-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RSDK-7497] Add WiFi provisioning #206
[RSDK-7497] Add WiFi provisioning #206
Conversation
net::{Ipv4Addr, TcpListener, UdpSocket}, | ||
}; | ||
|
||
async fn dns_server() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really happy to pull an entire crate just to do DNS so I will sync with clint & ale to check if we can do some mDNS approach
ssid: ssid.to_owned(), | ||
pwd: password.to_owned(), | ||
}) | ||
.map_err(|_| EspError::from_non_zero(NonZeroI32::new(1).unwrap()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this a placeholder for until I figure out the best approach to propagate errors
{ | ||
let mut conf = self.config.borrow_mut(); | ||
let (sta, _) = conf.as_mixed_conf_mut(); | ||
log::info!("attempting to connect to {} {}", ssid, password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove before merge
examples/esp32/esp32-server.rs
Outdated
@@ -142,7 +145,7 @@ mod esp32 { | |||
storage, | |||
info, | |||
repr, | |||
ip, | |||
std::net::Ipv4Addr::new(10, 1, 12, 187), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this IP address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bridge IP for qemu emulation
last_connection_attempt: Option<NetworkInfo>, | ||
provisioning_info: Option<ProvisioningInfo>, | ||
reason: ProvisioningReason, | ||
last_error: Option<String>, | ||
wifi_manager: Option<Wifi>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this saying that wifi_manager
is either None
or Some(())
?
Not sure what the purpose of the unit as the generic here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it needs to be resolvable to an object when its None otherwise rust can't properly do codegen
let rr = dns_message_parser::rr::RR::A(dns_message_parser::rr::A { | ||
domain_name: q.domain_name.clone(), | ||
ttl: 3600, | ||
ipv4_addr: Ipv4Addr::new(192, 168, 71, 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the default AP Ip for now I am going to make it configurable
fn has_str(&self, key: &str) -> Result<bool, NVSStorageError> { | ||
let nvs = self.nvs.borrow(); | ||
Ok(nvs.str_len(key)?.is_some()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make has_key
obsolete? I don't see it used anywhere else and the errors from has_str
would be a superset of errors from has_key
examples/esp32/esp32-server.rs
Outdated
|
||
#[cfg(not(feature = "provisioning"))] | ||
{ | ||
let sys_loop_stack = EspSystemEventLoop::take().unwrap(); | ||
#[allow(clippy::redundant_clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
necessary? don't see a clone anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome!
just some questions and nits
use super::wifi_provisioning::Esp32WifiProvisioningBuilder; | ||
|
||
async fn dns_server(ap_ip: Ipv4Addr) { | ||
let socket = async_io::Async::<UdpSocket>::bind(([0, 0, 0, 0], 53)).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expect
with error message
let socket = async_io::Async::<UdpSocket>::bind(([0, 0, 0, 0], 53)).unwrap(); | ||
loop { | ||
let mut buf = [0_u8; 512]; | ||
let len = socket.recv_from(&mut buf).await.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expect
instead of unwrap
let buf = msg.encode().unwrap(); | ||
socket.send_to(&buf, len.1).await.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expect
over unwrap
ServerError: From<<S as RobotCredentialStorage>::Error>, | ||
<S as WifiCredentialStorage>::Error: Sync + Send + 'static, | ||
{ | ||
let _ = Timer::after(std::time::Duration::from_millis(150)).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of this delay? comment would be nice
let wifi = Esp32WifiProvisioningBuilder::default() | ||
.build(storage.clone()) | ||
.await | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expect
over unwrap
let mut client = builder.build().await?; | ||
let certs = client.get_certificates().await?; | ||
|
||
let serv_key = CString::new(certs.tls_private_key).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expect
over unwrap
let serv_key: *const u8 = serv_key.into_raw() as *const u8; | ||
|
||
let tls_certs = CString::new(certs.tls_certificate) | ||
.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expect over unwrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion, LGTM.
Add support for the full configuration flow using Viam APP including setting up the WiFi. For now credentials are stored into memory only but they will be moved to NVS before the PR is merged.
I will wait for the internet connectivity PR to be merged first