drogue-es-wifi

Crates.iodrogue-es-wifi
lib.rsdrogue-es-wifi
version0.1.2
sourcesrc
created_at2020-10-12 14:50:58.164642
updated_at2020-10-12 17:39:44.228705
descriptionInventek eS-WiFi offload board interface via SPI
homepage
repositoryhttps://github.com/drogue-iot/drogue-es-wifi
max_upload_size
id298770
size47,572
Bob McWhirter (bobmcwhirter)

documentation

README

crates.io docs.rs Matrix

drogue-es-wifi

Driver for the Inventek eS-WiFi SPI WiFi offload board.

Usage

The eS-WiFi board is interfaced over an SPI peripheral, plus a handful of additional pins:

  • SPI
    • SCK
    • CIPO
    • COPI
  • chip-select
  • ready
  • wake-up
  • reset

Pins

Gather and configure your SPI and non-SPI pins appropriately for your particular chipset:

let sck = gpioc.pc10.into_af6(&mut gpioc.moder, &mut gpioc.afrh);

let cipo = gpioc.pc11.into_af6(&mut gpioc.moder, &mut gpioc.afrh);

let copi = gpioc.pc12.into_af6(&mut gpioc.moder, &mut gpioc.afrh);

let mut cs = gpioe.pe0.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);

let mut ready = gpioe.pe1.into_pull_up_input(&mut gpioe.moder, &mut gpioe.pupdr);

let mut reset = gpioe.pe8.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);

let mut wakeup = gpiob.pb13.into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper);

let mut spi = Spi::spi3(
    device.SPI3,
    (sck, cipo, copi),
    MODE,
    20.mhz(),
    clocks,
    &mut rcc.apb1r1,
);

Clock

An embedded-time Clock is required in order to provide appropriate delays and timeouts. The drogue-embedded-timer crate provides utilities and instructions for managing clocks.

Initialization

One the SPI peripheral and additional pins and clock are initialized, you can initialize the WiFi adapter:

let wifi = drogue_es_wifi::adapter::Adapter::new(
    spi,
    cs,
    ready,
    wakeup,
    reset,
    &CLOCK,
).unwrap();

Join an access point

The &CLOCK must be ticking forward prior to using the adapter.

To join a WEP-secured access-point:

let response = wifi.join_wep("drogue", "rodneygnome");

TCP connections

The adapter directly implements the drogue-network TcpStack:

let remote = HostSocketAddr::new(
    HostAddr::new(IpAddr::from_str("192.168.1.245").unwrap(), Option::None),
    80,
);

let mut socket = wifi.open(drogue_network::tcp::Mode::Blocking).unwrap();
let mut socket = wifi.connect(socket, remote).unwrap();

let len = wifi.write(&mut socket, b"GET / HTTP/1.1\r\nhost:192.168.1.245\r\n\r\n").unwrap();

loop {
    let mut buffer: [u8; 1024] = [0; 1024];
    let result = wifi.read(&mut socket, &mut buffer);

    match result {
        Ok(len) => {
            let s = core::str::from_utf8(&buffer[0..len]).unwrap();
            log::info!( "{}", s);
        }
        Err(e) => {
            match e {
                Error::Other(e) => {
                    log::error!("error {:?}", e);
                    break;
                }
                Error::WouldBlock => {
                }
            }
        }
    }
}

wifi.close(socket).unwrap();
Commit count: 17

cargo fmt