hp-core: add wifi connection
Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
This commit is contained in:
@@ -25,12 +25,12 @@ embedded-io-async = "0.6.1"
|
||||
embedded-storage = "0.3.1"
|
||||
esp-alloc = "0.6.0"
|
||||
esp-backtrace = { version = "0.15.0", features = ["esp32c6", "exception-handler", "panic-handler", "println"] }
|
||||
esp-hal = { version = "0.23.1", features = ["log"] }
|
||||
esp-hal = { version = "0.23.1", features = ["esp32c6", "log"] }
|
||||
esp-hal-embassy = { version = "0.6.0", optional = true }
|
||||
esp-ieee802154 = { version = "0.5.0", optional = true }
|
||||
esp-println = { version = "0.13.0", features = ["log"] }
|
||||
esp-storage = { version = "0.4.0", optional = true }
|
||||
esp-wifi = { version = "0.12.0", features = ["log"], optional = true }
|
||||
esp-wifi = { version = "0.12.0", features = ["log", "utils", "wifi"] }
|
||||
heapless = "0.8.0"
|
||||
hmac = { version = "0.12.1", default-features = false }
|
||||
ieee80211 = { version = "0.4.0", default-features = false }
|
||||
@@ -52,14 +52,8 @@ edge-nal-embassy = { version = "0.5.0" }
|
||||
[features]
|
||||
default=["esp32c6"]
|
||||
|
||||
esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-hal-embassy?/esp32", "esp-println/esp32", "esp-storage?/esp32", "esp-wifi?/esp32"]
|
||||
esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-hal-embassy?/esp32c2", "esp-println/esp32c2", "esp-storage?/esp32c2", "esp-wifi?/esp32c2", ]
|
||||
esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-hal-embassy?/esp32c3", "esp-println/esp32c3", "esp-storage?/esp32c3", "esp-wifi?/esp32c3"]
|
||||
esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-hal-embassy?/esp32c6", "esp-println/esp32c6", "esp-storage?/esp32c6", "esp-wifi?/esp32c6", "esp-ieee802154?/esp32c6"]
|
||||
esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-hal-embassy?/esp32h2", "esp-println/esp32h2", "esp-storage?/esp32h2", "esp-wifi?/esp32h2", "esp-ieee802154?/esp32h2"]
|
||||
esp32s2 = ["esp-hal/esp32s2", "esp-backtrace/esp32s2", "esp-hal-embassy?/esp32s2", "esp-println/esp32s2", "esp-storage?/esp32s2", "esp-wifi?/esp32s2"]
|
||||
esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-hal-embassy?/esp32s3", "esp-println/esp32s3", "esp-storage?/esp32s3", "esp-wifi?/esp32s3"]
|
||||
esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-hal-embassy?/esp32c6", "esp-println/esp32c6", "esp-storage?/esp32c6", "esp-wifi/esp32c6", "esp-ieee802154?/esp32c6"]
|
||||
|
||||
esp-wifi = ["dep:esp-wifi"]
|
||||
# esp-wifi = ["dep:esp-wifi"]
|
||||
|
||||
embassy = ["dep:esp-hal-embassy"]
|
||||
# embassy = ["dep:esp-hal-embassy"]
|
||||
|
@@ -1,45 +1,149 @@
|
||||
//! This shows a very basic example of running code on the LP core.
|
||||
//!
|
||||
//! Code on LP core increments a counter and continuously toggles LED. The
|
||||
//! current value is printed by the HP core.
|
||||
//!
|
||||
//! Make sure to first compile the `esp-lp-hal/examples/blinky.rs` example
|
||||
//!
|
||||
//! The following wiring is assumed:
|
||||
//! - LED => GPIO1
|
||||
|
||||
//% CHIPS: esp32c6
|
||||
//% FEATURES: esp-hal/unstable
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use blocking_network_stack::Stack;
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{
|
||||
gpio::lp_io::{LowPowerInput, LowPowerOutput},
|
||||
clock::CpuClock,
|
||||
gpio::lp_io::{
|
||||
LowPowerInput,
|
||||
LowPowerOutput},
|
||||
load_lp_code,
|
||||
lp_core::{LpCore, LpCoreWakeupSource},
|
||||
lp_core::{
|
||||
LpCore,
|
||||
LpCoreWakeupSource
|
||||
},
|
||||
main,
|
||||
rtc_cntl::{sleep::WakeFromLpCoreWakeupSource, Rtc},
|
||||
uart::{Config, lp_uart::LpUart}
|
||||
rng::Rng,
|
||||
// rtc_cntl::{
|
||||
// sleep::WakeFromLpCoreWakeupSource,
|
||||
// Rtc
|
||||
// },
|
||||
time::{
|
||||
self
|
||||
},
|
||||
timer::timg::TimerGroup,
|
||||
uart::{
|
||||
Config,
|
||||
lp_uart::LpUart
|
||||
}
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_println::{
|
||||
print,
|
||||
println
|
||||
};
|
||||
use esp_wifi::{
|
||||
init,
|
||||
wifi::{
|
||||
utils::create_network_interface,
|
||||
AccessPointInfo,
|
||||
ClientConfiguration,
|
||||
Configuration,
|
||||
WifiError,
|
||||
WifiStaDevice,
|
||||
}
|
||||
};
|
||||
use smoltcp::{
|
||||
iface::{
|
||||
SocketSet,
|
||||
SocketStorage
|
||||
},
|
||||
wire::DhcpOption
|
||||
};
|
||||
|
||||
const SSID: &str = env!("SSID");
|
||||
const PASSWORD: &str = env!("PASSWORD");
|
||||
|
||||
fn as_millis() -> u64 {
|
||||
time::now().duration_since_epoch().to_millis()
|
||||
}
|
||||
|
||||
#[main]
|
||||
fn main() -> ! {
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
let mut rng = Rng::new(peripherals.RNG);
|
||||
let init = init(timg0.timer0, rng, peripherals.RADIO_CLK).unwrap();
|
||||
let mut wifi = peripherals.WIFI;
|
||||
let (iface, device, mut controller) =
|
||||
create_network_interface(&init, &mut wifi, WifiStaDevice).unwrap();
|
||||
controller
|
||||
.set_power_saving(esp_wifi::config::PowerSaveMode::None)
|
||||
.unwrap();
|
||||
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
|
||||
let mut socket_set = SocketSet::new(&mut socket_set_entries[..]);
|
||||
let mut dhcp_socket = smoltcp::socket::dhcpv4::Socket::new();
|
||||
// we can set a hostname here (or add other DHCP options)
|
||||
dhcp_socket.set_outgoing_options(&[DhcpOption {
|
||||
kind: 12,
|
||||
data: b"esp32-c6",
|
||||
}]);
|
||||
socket_set.add(dhcp_socket);
|
||||
|
||||
let stack = Stack::new(iface, device, socket_set, as_millis, rng.random());
|
||||
let client_config = Configuration::Client(ClientConfiguration {
|
||||
ssid: SSID.try_into().unwrap(),
|
||||
password: PASSWORD.try_into().unwrap(),
|
||||
..Default::default()
|
||||
});
|
||||
let res = controller.set_configuration(&client_config);
|
||||
println!("wifi_set_configuration returned {:?}", res);
|
||||
|
||||
controller.start().unwrap();
|
||||
println!("is wifi started: {:?}", controller.is_started());
|
||||
|
||||
println!("Start Wifi Scan");
|
||||
let res: Result<(heapless::Vec<AccessPointInfo, 10>, usize), WifiError> = controller.scan_n();
|
||||
if let Ok((res, _count)) = res {
|
||||
for ap in res {
|
||||
println!("{:?}", ap.ssid);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{:?}", controller.capabilities());
|
||||
println!("wifi_connect {:?}", controller.connect());
|
||||
|
||||
// wait to get connected
|
||||
println!("Wait to get connected");
|
||||
loop {
|
||||
match controller.is_connected() {
|
||||
Ok(true) => break,
|
||||
Ok(false) => {}
|
||||
Err(err) => {
|
||||
println!("{:?}", err);
|
||||
// FIXME: Error handling
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("{:?}", controller.is_connected());
|
||||
|
||||
// wait for getting an ip address
|
||||
println!("Wait to get an ip address");
|
||||
loop {
|
||||
stack.work();
|
||||
|
||||
if stack.is_iface_up() {
|
||||
println!("got ip {:?}", stack.get_ip_info());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let lp_pin = LowPowerOutput::new(peripherals.GPIO1);
|
||||
|
||||
let uart_cfg = Config::default();
|
||||
let tx = LowPowerOutput::new(peripherals.GPIO5);
|
||||
let rx = LowPowerInput::new(peripherals.GPIO4);
|
||||
let lp_uart = LpUart::new(peripherals.LP_UART, uart_cfg, tx, rx);
|
||||
|
||||
let mut rtc = Rtc::new(peripherals.LPWR);
|
||||
let reason = WakeFromLpCoreWakeupSource::default();
|
||||
|
||||
// let mut rtc = Rtc::new(peripherals.LPWR);
|
||||
// let reason = WakeFromLpCoreWakeupSource::default();
|
||||
let mut lp_core = LpCore::new(peripherals.LP_CORE);
|
||||
|
||||
lp_core.stop();
|
||||
println!("lp-core -> stop");
|
||||
|
||||
|
Reference in New Issue
Block a user