Code Monkey home page Code Monkey logo

wifimulti_rs's Introduction

WifiMulti for Rust on ESP32

This crate is a simple Wifi connection manager for Rust projects on the ESP32 architecture, inspired by the Arduino library of the same name.

In a nutshell

use wifi_multi::WifiMulti;

fn main() {
    let mut wfm = WifiMulti::new();
    wfm.add("ssid1", "psk1")?;
    wfm.add("ssid2", "psk2")?;
    wfm.run()?;

    let s = wfm.state();
    println!("WifiMulti state {:?}", s);
    if s.is_ok() {
        info!("Connected to {:?}", wfm.connected_ssid());
    }
}

Details

The code aims to be fire-and-forget. Add your SSID data, call run(), that's it.

run() fires off a thread that scans for APs, selects the one with the strongest signal, connects, monitors the connection and tries to reconnect forever.

You can add as many SSIDs as you like (they're kept in a Vec), but only before you call run().

Note that run() returns immediately, before a connection is established. If you want to wait, use run_wait(timeout).

state() returns a Result, Ok(()) when there is a connection and Err(WifiMulti::Error) otherwise.

Shortcomings

There are hardcoded timeouts.

It always tries to connect to the SSID with the strongest signal; if that fails (e.g. because the PSK is wrong), it will try over and over and never look at other configured SSIDs.

I'm very new to Rust.

wifimulti_rs's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.