Giter Club home page Giter Club logo

esp-wifi-config's Introduction

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: ::

#include <stdio.h>
#include <esp/uart.h>

#include "wifi_config.h"


void on_wifi_event(wifi_config_event_t event) {
    if (event == WIFI_CONFIG_CONNECTED) {
        printf("Connected to WiFi\n");
    } else if (event == WIFI_CONFIG_DISCONNECTED) {
        printf("Disconnected from WiFi\n");
    }
}

void user_init(void) {
    uart_set_baud(0, 115200);

    wifi_config_init2("my-accessory", "my-password", on_wifi_event);
}

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.

pip install flask

Then run server with

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:

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

esp-wifi-config's People

Contributors

maximkulkin avatar rutger798 avatar stellarshenson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-wifi-config's Issues

WIFI_CONFIG_CONNECT_TIMEOUT Issue

Am I correct that (xTaskGetTickCount() - context->connect_start_time) should be divided by portTICK instead of multiplied?

static void wifi_config_sta_connect_timeout_callback(void *arg) {

    if (sdk_wifi_station_get_connect_status() == STATION_GOT_IP) {
        // Connected to station, all is dandy
        DEBUG("Successfully connected");
        sdk_os_timer_disarm(&context->sta_connect_timeout);

        wifi_config_softap_stop();
        if (context->on_wifi_ready)
            context->on_wifi_ready();
        wifi_config_context_free(context);
        context = NULL;
        return;
    }

    if ((xTaskGetTickCount() - context->connect_start_time) * portTICK_PERIOD_MS < WIFI_CONFIG_CONNECT_TIMEOUT) {
        // Still have time, continue trying
        return;
    }

    sdk_os_timer_disarm(&context->sta_connect_timeout);
    DEBUG("Timeout connecting to WiFi network, starting config AP");
    // Not connected to station, launch configuration AP
    wifi_config_softap_start();
}

Wifi Client mode >> Wifi AP mode >> Wifi Client mode

Hi Maxim,

as far as I understand, when an already paired device restarts, it tries to reconnect to the last known Wifi SSID for xxx seconds (DWIFI_CONFIG_CONNECT_TIMEOUT=xxx) and then if it does not succeed it turns into AP mode.

I was wondering if it's possible to create a timeout for the period operating in AP mode. For example a device could stay in AP and wait for any connections and then if nothing happens for i.e. 5-10 minutes it would try to reconnect again to the last known Wifi network.

In the current implementation if for whatsoever reason the device does not connect to Wifi SSID, it turns into AP mode and stays there until you physically disconnect it from the mains. Having to power reset a device in such situation is sometimes tricky or difficult (i.e. in cases that a device is installed into an electrical box etc).

Similar discussions here: RavenSystem/esp-homekit-devices#169

and here RavenSystem/esp-homekit-devices#164

Thank you,
Yiannis

SSID with special character

Hello,

If the ssid contain a '&' within the name the configuration fail because of the post form will fill the value with &so the ssid is wrong and unable to connect to the wifi network.

ssid bug

As a workaround, you can post the rights values with postman for example.
in the body x-www-form-urlencoded with ssid and password keys.

Config not being applied

Not sure where to ask, so will try here. I did get the wifi config popup, selected my AP in the list, entered the password and clicked "join", but the config doesn't seem to be applied, as the Sonoff AP is still visible. This is what I see in the console log:

wifi_config: http_task: Got 64 incomming data
wifi_config: http_task: Got 16 incomming data
wifi_config: wifi_config_server_on_settings_update: Update settings, body = ssid=dodies&password=mypasswordhere
wifi_config: wifi_config_station_connect: No configuration found
wifi_config: Client disconnected
scandone
scandone

What am I doing wrong?

Does this work on ESP32?

I am quite a newbie with building and modifying projects of this size, but would like to know if I can use this directly with the homekit-demo examples/esp32/led in the same way that it was used in sonoffbasic. Will the button.c work as well? How hardware specific is the code between esp8266 and esp32? Can I just copy and modify the code from within the esp32 directory with the same makefile and it will build as expected?

Question: local images

Hi! Is it possible to upload .png images that shows up when the wi-fi config page loads?
I want to show my logo inside the captive portal.
Is it possible? If yes, any example avaible?

Thanks

Unneccesairy wait after connect

Current observation: there is an unnecessary (and long) wait after the IP is acquired
Suggestion: add a callback related to assignment of IP and set a semaphore which does the waiting instead of a timer...

connected with xxx, channel 6
dhcp client start...
ip:192.168.178.109,mask:255.255.255.0,gw:192.168.178.1
>>> wifi_config: wifi_config_sta_connect_timeout_callback: Successfully connected

Feature request: RSSI, BSSID, Channel info on network selection page

The idea comes from Ravensystem who recently implemented it into his HAA firmware (1.6.0~1.6.3)

quoting from his change log:

Setup Mode: Added RSSI and BSSID information to WiFi Scanner.
Setup Mode: WiFi Scanner now shows all WiFi even if different APs have same SSID.
Setup Mode: Added option to force WiFi to connect to a specific WiFi BSSID.

It would be very helpful if it was possible to have channel and RSSI, BSSID information of the available wifi networks. Based on that information, the user could make informed decisions, on which network to select. This information makes sense when Powerline(s), or Wifi Extender(s) are used which all share the same SSID. The user could instruct the esp device to always connect to a specific BSSID which has stronger signal. Or maybe, for whatever reason, there is a need to avoid an extender which is closer to the esp device and has very strong signal.

Having this feature will give more control to users who might experience connectivity issues.

unwanted line ending in embed.py

Realy nice Repo!!!!

The embed.py is not working properly for me the resulting HTML (index.html.h) code contains a unwanted line ending.

const char *html_settings_header = 
"<!DOCTYPE html>
"
"<html>
"
"<head>
"

By changing the below line with a extra strip it works for me

    def process_part(part):
        return "\n".join(
-            "\"" + line.lstrip().replace('"', '\\"') + "\""
+            "\"" + line.lstrip().replace('"', '\\"').strip() + "\""
            for line in part.split("\n")
                if line.strip()
        )

Result:

const char *html_settings_header = 
"<!DOCTYPE html>"
"<html>"
"<head>"

Is this something you can fix, ore should i create a pull request?

wifi restart

When I restart my router, I notice that my thermostats are restarting.
I still have not checked what causes the restart and first decided to ask if it is possible for the library to restart the device when I restart the wifi router?

WIFI_CONFIG_CONNECT_TIMEOUT too short to recover from power failures

I have a persistent problem with power failures, my ESP's never recover from them because my router need a lot more time to start than the ESP, so it never connects. I usually have to disarm a circuit breaker to make it connect or do the softAp config again...

I raised the WIFI_CONFIG_CONNECT_TIMEOUT to 300000 and now the router have enough time to return online, I think 15 seconds is not sufficient time to a number of routers to boot up.

What do you think about raising the timeout on the library?
The trade-offs will not affect the setup process because as the softAp starts immediately when there is no saved config.

Add disconnect callback?

Hi Maxim,
this light version of WifiManager is amazing, but it is possible to have on your wifi_config_init() a callback also for wifi disconnect event?

Thanks in advance

Memory leak during AP mode

There seems to be a memory leak somewhere when the esp-wifi-config goes into AP mode. When combining it with esp-homekit, this causes the SRP shared secret to fail.

The free heap before the shared secret fails AP mode is 21888
The free heap before the shared secret is created without AP Mode is 30324

White screen after selecting wifi

There seems to be an issue on current iOS, and even macOS, where after selecting your wifi AP and clicking the Join button you get a white screen and it never goes away. Highly repeatable.

hidden network

any way connecting to hidden ssid with

wifi_config_init("my-accessory", "my-password", on_wifi_ready);

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.