Coder Social home page Coder Social logo

seeed-studio / seeed_arduino_rpcwifimanager Goto Github PK

View Code? Open in Web Editor NEW
3.0 13.0 1.0 55 KB

A software library for configuring device networks using AP mode.

License: MIT License

HTML 11.10% JavaScript 3.99% C 5.69% C++ 79.22%
arduino-library ap wifi network wifimanager wioterminal

seeed_arduino_rpcwifimanager's Introduction

WiFiManager

Wio Terminal WiFi Connection Manager with fallback Web Configuration Portal.

The configuration portal is of the captive variety, so on various devices it will present the configuration dialogue as soon as you connect to the created access point.

Library Dependencies

How It Looks

ESP8266 WiFi Captive Portal Homepage ESP8266 WiFi Captive Portal Configuration

Using

  • Include in your sketch
//needed for library
#include <rpcWiFi.h>
#include <DNSServer.h>
#include <WebServer.h>
#include <WiFiManager.h>  
  • Initialize library, in your setup function add
WiFiManager wifiManager;
  • Also in the setup function add
//first parameter is name of access point, second is the password
wifiManager.autoConnect("AP-NAME", "AP-PASSWORD");

if you just want an unsecured access point

wifiManager.autoConnect("AP-NAME");

or if you want to use and auto generated name from 'ESP' and the esp's Chip ID use

wifiManager.autoConnect();

After you write your sketch and start the ESP, it will try to connect to WiFi. If it fails it starts in Access Point mode. While in AP mode, connect to it then open a browser to the gateway IP, default 192.168.1.1, configure wifi, save and it should reboot and connect.

Also see examples.

Documentation

Password protect the configuration Access Point

You can and should password protect the configuration access point. Simply add the password as a second parameter to autoConnect. A short password seems to have unpredictable results so use one that's around 8 characters or more in length. The guidelines are that a wifi password must consist of 8 to 63 ASCII-encoded characters in the range of 32 to 126 (decimal)

wifiManager.autoConnect("AutoConnectAP", "password")

Callbacks

Enter Config mode

Use this if you need to do something when your device enters configuration mode on failed WiFi connection attempt. Before autoConnect()

wifiManager.setAPCallback(configModeCallback);

configModeCallback declaration and example

void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  Serial.println(WiFi.softAPIP());

  Serial.println(myWiFiManager->getConfigPortalSSID());
}
Save settings

This gets called when custom parameters have been set AND a connection has been established. Use it to set a flag, so when all the configuration finishes, you can save the extra parameters somewhere.

wifiManager.setSaveConfigCallback(saveConfigCallback);

saveConfigCallback declaration and example

//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

Configuration Portal Timeout

If you need to set a timeout so the ESP doesn't hang waiting to be configured, for instance after a power failure, you can add

wifiManager.setConfigPortalTimeout(180);

which will wait 3 minutes (180 seconds). When the time passes, the autoConnect function will return, no matter the outcome.

Check for connection and if it's still not established do whatever is needed (on some modules I restart them to retry, on others I enter deep sleep)

Custom Parameters

You can use WiFiManager to collect more parameters than just SSID and password. This could be helpful for configuring stuff like MQTT host and port, blynk or emoncms tokens, just to name a few.

You are responsible for saving and loading these custom values. The library just collects and displays the data for you as a convenience.

Usage scenario would be:

  • load values from somewhere (EEPROM/FS) or generate some defaults
  • add the custom parameters to WiFiManager using
// id/name, placeholder/prompt, default, length
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
wifiManager.addParameter(&custom_mqtt_server);
  • if connection to AP fails, configuration portal starts and you can set /change the values (or use on demand configuration portal)

  • once configuration is done and connection is established save config callback is called

  • once WiFiManager returns control to your application, read and save the new values using the WiFiManagerParameter object.

mqtt_server = custom_mqtt_server.getValue();

You should also take a look at adding custom HTML to your form.

Custom HTML, CSS, Javascript

There are various ways in which you can inject custom HTML, CSS or Javascript into the configuration portal. The options are:

  • inject custom head element

You can use this to any html bit to the head of the configuration portal. If you add a <style> element, bare in mind it overwrites the included css, not replaces.

wifiManager.setCustomHeadElement("<style>html{filter: invert(100%); -webkit-filter: invert(100%);}</style>");
  • inject a custom bit of html in the configuration form
WiFiManagerParameter custom_text("<p>This is just a text paragraph</p>");
wifiManager.addParameter(&custom_text);
  • inject a custom bit of html in a configuration form element

Just add the bit you want added as the last parameter to the custom parameter constructor.

WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "iot.eclipse", 40, " readonly");

Filter Networks

You can filter networks based on signal quality and show/hide duplicate networks.

  • If you would like to filter low signal quality networks you can tell WiFiManager to not show networks below an arbitrary quality %;
wifiManager.setMinimumSignalQuality(10);

will not show networks under 10% signal quality. If you omit the parameter it defaults to 8%;

  • You can also remove or show duplicate networks (default is remove). Use this function to show (or hide) all networks.
wifiManager.setRemoveDuplicateAPs(false);

Contributions and thanks

The support and help I got from the community has been nothing short of phenomenal. I can't thank you guys enough. This is my first real attempt in developing open source stuff and I must say, now I understand why people are so dedicated to it, it is because of all the wonderful people involved.

THANK YOU

zhouhan0126

Shawn A

Maximiliano Duarte

alltheblinkythings

Niklas Wall

Jakub Piasecki

Peter Allan

John Little

markaswift

franklinvv

Alberto Ricci Bitti

SebiPanther

jonathanendersby

walthercarsten

Sorry if i have missed anyone.

Inspiration

seeed_arduino_rpcwifimanager's People

Contributors

ansonhe97 avatar pillar1989 avatar zhouhan0126 avatar

Stargazers

 avatar  avatar  avatar

Watchers

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

Forkers

lalittech

seeed_arduino_rpcwifimanager's Issues

Disconnected from access point during network scan

Describe the bug
I have confirmed the operation of Captive Portal using examples/AutoConnect, but when I click "Configure WiFi" on my PC (Windows 10), network is disconnected from the access point (Wio Terminal) and the SSID and password setting screen is not displayed.
There is no problem with "Configure Wifi (No Scan)".

image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Google Chrome or Microsoft Edge

Additional context

int n = WiFi.scanNetworks();

- int n = WiFi.scanNetworks();
+ int n = 0;

When I changed the program as described above, the network was not disconnected from the access point (Wio Terminal).

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.