项目作者: maximkulkin

项目描述 :
Library to bootstrap WiFi-enabled accessories WiFi config
高级语言: C
项目地址: git://github.com/maximkulkin/esp-wifi-config.git
创建时间: 2018-01-05T01:06:02Z
项目社区:https://github.com/maximkulkin/esp-wifi-config

开源协议:MIT License

下载


esp-wifi-config

Library for esp-open-rtos to bootstrap WiFi-enabled accessories WiFi config

Library uses sysparams to store configuration. When you initialize it
it tries to connect to configured WiFi network. If no configuration exists or
network is not available, it starts it’s own WiFi AP (with given name and
optional password). AP runs a captive portal, so when user connects to it a
popup window is displayed asking user to select one of WiFi networks that are
present in that location (and a password if network is secured) and configures
device to connect to that network.

After successful connection it calls provided callback so you can continue
accessory initializiation.

Example: ::

  1. #include <stdio.h>
  2. #include <esp/uart.h>
  3. #include "wifi_config.h"
  4. void on_wifi_event(wifi_config_event_t event) {
  5. if (event == WIFI_CONFIG_CONNECTED) {
  6. printf("Connected to WiFi\n");
  7. } else if (event == WIFI_CONFIG_DISCONNECTED) {
  8. printf("Disconnected from WiFi\n");
  9. }
  10. }
  11. void user_init(void) {
  12. uart_set_baud(0, 115200);
  13. wifi_config_init2("my-accessory", "my-password", on_wifi_event);
  14. }

Custom HTML

If you want a custom look, you can provide your own HTML for WiFi settings page.
To do that, in your project’s Makefile define variable WIFI_CONFIG_INDEX_HTML with
path to your custom HTML file.

UI Development

UI content is located in content/index.html (which is actually Jinja2 template).
To simplify UI development this there is a simple server you can use to see
how HTML will be rendered. To run it, you will need Python runtime and Flask python
package.

  1. pip install flask

Then run server with

  1. tools/server.py

and connect to http://localhost:5000/settings with your browser. That URL shows
how settings page will look like with some combination of secure & unsecure
networks. http://localhost:5000/settings0 URL shows page when no WiFi networks
could be found.

On build template code will be split into parts (marked with <!-- part PART_NAME --> comments). In all parts all Jinja code blocks ({% %}) are removed and all
output blocks ({{ }}) are replaced with %s. HTML_SETTINGS_HEADER and
HTML_SETTINGS_FOOTER parts are output as-is while HTML_NETWORK_ITEM is assumed to
have two %s placeholders, first of which will be “secure” or “unsecure” and
second one - name of a WiFi network.

To run server against your custom HTML, set environment variable
WIFI_CONFIG_INDEX_HTML before your run tools/server.py:

  1. export WIFI_CONFIG_INDEX_HTML=my_wifi_config.html
  2. path/to/your/wifi-config/tools/server.py