-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
69 lines (51 loc) · 1.64 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#![allow(unused_imports)]
#![allow(clippy::single_component_path_imports)]
mod wifi;
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
use std::sync::{Condvar, Mutex};
use std::{cell::RefCell, env, sync::atomic::*, sync::Arc, thread, time::*};
use anyhow::bail;
use anyhow::Result;
use log::*;
use embedded_svc::utils::anyerror::*;
use esp_idf_svc::netif::*;
use esp_idf_svc::nvs::*;
use esp_idf_svc::ping;
use esp_idf_svc::sysloop::*;
use esp_idf_svc::wifi::*;
use esp_idf_hal::prelude::*;
use esp_idf_sys;
use esp_idf_sys::esp;
fn main() -> Result<()> {
esp_idf_sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
// Get backtraces from anyhow; only works for Xtensa arch currently
// TODO: No longer working with ESP-IDF 4.3.1+
//#[cfg(target_arch = "xtensa")]
//env::set_var("RUST_BACKTRACE", "1");
#[allow(unused)]
let netif_stack = Arc::new(EspNetifStack::new()?);
#[allow(unused)]
let sys_loop_stack = Arc::new(EspSysLoopStack::new()?);
#[allow(unused)]
let default_nvs = Arc::new(EspDefaultNvs::new()?);
#[allow(clippy::redundant_clone)]
#[cfg(not(feature = "qemu"))]
#[allow(unused_mut)]
thread::spawn(move || {
let mut wifi_state = wifi::wifi(
netif_stack.clone(),
sys_loop_stack.clone(),
default_nvs.clone(),
);
match wifi_state {
Ok(_) => info!("Wifi connected"),
Err(err) => warn!("wifi failed: {}", err)
};
});
thread::sleep(Duration::from_secs(20));
info!("hello world");
Ok(())
}