Managing Configurations on Your ESP8266 Using WiFiManager

7,988

40

3.

Introduction: Managing Configurations on Your ESP8266 Using WiFiManager

关于:嘿大家!我的名字是Brian,谢谢你检查我的赋予奖。我是一位通过交易的软件开发人员,但我最近发现了ASP8266芯片后的Arduino开发,一个WiFi启用......

Hello everyone!

在以前的指导,我谈到了避免使用伟大的esp8266上的硬编码wifi凭据WifiManager Library

您还可以使用图书馆管理Arduino sketch's configurations and in this instructable I'm going to show you how. There is a little more setup steps than the WiFi Credentials Instructable, but it's still very straight forward.

Check out the video or continue reading here to find out how to add it and how it works.

Step 1: What's the Advantage of This?

特别是在添加网络功能时,草图包含大量配置值,例如API键或服务器地址。

Normally you would need to re-program your device to change these values, but using WiFiManager you can configure them easily.

It also makes your sketches more shareable, as you really don't want to be checking in your API Keys, like I have many many times!

第2步:你的草图需要什么

You sketch will need a couple of things to achieve this setup.

在正常行为中,WiFimanager将启动配置模式如果它无法连接到WiFi网络,这对于仅为WiFi凭据,但如果您提供其他配置,则需要能够按需启动WiFimanager配置模式。最简单的方法是使用一个按钮。

您的草图需要的另一件事是能够持续到您的设备的重新启动配置的能力,我认为最好的做法是使用壳。最后一步中的示例中的代码有用于读取和保存配置的方法,以便您想要了解更多关于IT的Andreas Spiess(瑞士口音的家伙)a really good video on it

Step 3: How It Looks With Configurations

当在设备上激活配置模式时,通过无法连接到先前已知的网络或按下按钮的用户,它将创建一个您将连接到的adhoc网络。

在浏览器上连接任何请求后,将自动重定向到设备配置门户。

From here you can enter the details of the WiFi Network you want to connect to, and also set the configurations.

第4步:将其他配置添加到Wifimanager

现在所做的一切都是显示给Wifimanager门户添加这些附加配置。我将从我的arduino-youtube-api库中使用一个例子来显示它的工作。

I'm not going to through all the sketch, but if you have any questions please do ask in the comments!

Note: Each step here corresponds with one of the images from above.

  1. The first thing you'll see is the "setSaveConfigCallback" which basically is just a method that sets the flag that lets the sketch know it needs to save the config.
  2. 第二件事是WifimanagerParameters,您需要为您想要的每种附加配置初始化一个。这需要4个输入:
    1. ID(不是非常重要的,只是让它独特)
    2. 占位符(图像3中所示的示例)
    3. Default value (as shown in Image 4)
    4. 最大长度(限制用户输入的值的长度)
  3. You then can read the values from the WiFiManagerParameters using the "getValue()" method.
  4. The autoConnect line is where you set the name of the adhoc access point that you want config mode to broadcast, I've also added a password to it for additional security.

Hopefully you find this useful and as always if you have any questions please ask!

谢谢,

布莱恩

是第一个分享

    建议书

    • 词干比赛

      词干比赛
    • 角色扮演游戏挑战

      角色扮演游戏挑战
    • CNC竞赛

      CNC竞赛

    3评论

    0.
    gcalhoun49.

    问题1年前Introduction

    I am trying to update an old project and found that I need wifimanager. I would like my project to run through a router if available or as an AP if no router is available. I just finished reading your instructable and will follow it to update my code. My question is: Can I let wifimanager try to connect, fail, then go into AP mode, load my web page and run normally? The page would have a button to initiate config mode , if needed, rather than having to modify my hardware to add a button.

    0.
    cjrodriguez.

    问题2 years ago

    Hi Brian! Un this project you used WifiManager to set YouTube credentials with YouTube Api. Do you know if there is or exist for Adafruit mqtt credentials?
    此致

    0.
    Ludmina

    3年前

    嗨Brian,

    I have the sketch like below :

    #include

    #include

    #include

    //#包括

    // Fill in your WiFi router SSID and password

    const char *ssid = "suzuki";

    const char *password = "12345678";

    // mdnsresponder mdns;

    ESP8266WebServer server(80);

    const char index_html [] =

    “<!doctype html>”

    “”

    ""

    "Suzuki Wagon R+ "

    "