Git Product home page Git Product logo

wifimanagerext's Introduction

WiFiManagerExt

Présentation

WiFiManagerExt est une extension de WiFiManager permettant d'intégrer un bouton pour effectuer un effacement des paramètres WiFi.

Lien : WiFiManager

Cela fonctionne pour une carte ESP32 avec la plateforme Arduino : https://github.com/espressif/arduino-esp32.

Utilisation

La broche du bouton utilisé se fait à l'instanciation :

#include <WiFiManagerExt.h>

#define GPIO_X x // Button

WiFiManagerExt wm(GPIO_X); // use the button on GPIO_X to perform a default reset

Sinon, c'est le bouton nommé BOOT (GPIO0) qui est utilisé par défaut :

#include <WiFiManagerExt.h>

WiFiManagerExt wm; // use the BOOT button to perform a default reset

Il faut maintenir l'appui pendant un certain temps pour déclencher la prise en compte du reset. Ce temps est fixé à 3 secondes par défaut. On peut le modifier avec setHoldResetButtonTime().

La prise en compte du reset se fait en appelant isDefaultReset() dans loop(). Cela déclenchera un effacement des paramètres WiFi et un redémarrage si setActiveDefaultReset(true) a été réalisé. Sinon, il est possible d'installer une fonction de rappel pour programer sa propre séquence de reset :

void doReset()
{  
    wm.defaultReset();
}

wm.setDefaultResetCallback(doReset);

Pour le reste, c'est WiFiManager qui effectue le travail.

WiFiManagerExt

Exemple d'utilisation

#include <WiFiManagerExt.h> // https://github.com/tvaira/WiFiManagerExt

WiFiManagerExt wm; // use the BOOT button to perform a default reset

void doReset() {  
    wm.defaultReset();
}

void setup() {
    WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP

    // put your setup code here, to run once:
    Serial.begin(115200);
    
    //reset settings - wipe credentials for testing
    //wm.resetSettings();

    wm.setTitle("BTS SN LaSalle Avignon");
    //wm.setDarkMode(true);

    // Automatically connect using saved credentials,
    // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
    // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
    // then goes into a blocking loop awaiting configuration and will return success result

    bool res;
    res = wm.autoConnect(); // auto generated AP name from chipid
    // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
    //res = wm.autoConnect("AutoConnectAP","password"); // password protected ap

    if(!res) {
        Serial.println("Failed to connect");
        // ESP.restart();
    } 
    else {
        //if you get here you have connected to the WiFi    
        Serial.println("connected...yeey :)");
    }

    //wm.setHoldResetButtonTime(3); // keep pressing for at least 3 seconds (default)
    //wm.setBeforeResetTime(2); // wait 2 seconds before resetting the ESP32 card (default)
    //wm.setActiveDefaultReset(true); // active a default reset or use callback
    wm.setDefaultResetCallback(doReset);
}

void loop() {
    // put your main code here, to run repeatedly    

    // default reset request ?
    wm.isDefaultReset();
}

Pour la bibliothèque WiFiManager, voir aussi les exemples.

PlatformIO

Pour utiliser WiFiManagerExt avec PlatformIO, il faut l'indiquer dans le fichier platformio.ini comme ceci :

[env]
lib_deps =
	https://github.com/tvaira/WiFiManagerExt.git

Sinon, pour utiliser seulement WiFiManager :

[env]
lib_deps =
	https://github.com/tzapu/WiFiManager.git

wifimanagerext's People

Contributors

tvaira avatar

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.