Code Monkey home page Code Monkey logo

micropython-wifimanager's Introduction

micropython-wifimanager

A simple network configuration utility for MicroPython on boards such as ESP8266 and ESP32.

Configuration

Simply upload your JSON file with your networks, the default path is '/networks.json', which is specified in the class property config_file.

A sample configuration may look like this:

{
	"schema": 2,
	"known_networks": [
		{
			"ssid": "User\u2019s iPhone",
			"password": "Password1",
			"enables_webrepl": false
		},
		{
			"ssid": "HomeNetwork",
			"password": "Password2",
			"enables_webrepl": true
		}
	],
	"access_point": {
		"config": {
			"essid": "Micropython-Dev",
			"channel": 11,
			"hidden": false,
			"password": "P@55W0rd"
		},
		"enables_webrepl": true,
		"start_policy": "fallback"
	}
}

Configuration schema

  • schema: currently this should be 2
  • known_networks: list of networks to connect to, in order of most preferred first
    • SSID - the name of the access point
    • password - the clear test password to use
    • enables_webrepl - a boolean value to indicate if connection to this network desires webrepl being started
  • access_point: the details for the access point (AP) of this device
    • config - the keys for the AP config, exactly as per the micropython documentation
    • enables_weprepl - a boolean value to indicate if ceating this network desires webrepl being started
    • start_policy - A policy from the below list to indicate when to enable the AP
      • 'always' - regardless of the connection to any base station, AP will be started
      • 'fallback' - the AP will only be started if no network could be connected to
      • 'never' - The AP will not be started under any condition

Simple usage (one shot)

Here's an example of how to use the WifiManager.

MicroPython v1.9.4 on 2018-05-11; ESP32 module with ESP32
Type "help()" for more information.
>>> from wifi_manager import WifiManager
>>> WifiManager.setup_network()
connecting to network Foo-Network...
WebREPL daemon started on ws://10.1.1.234:8266
Started webrepl in normal mode
True

Asynchronous usage (event loop)

The WifiManager can be run asynchronously, via the cooperative scheduling that micropthon has in uasyncio. If you call WifiManager.start_managing() as follows, it will ensure that periodically the network status is scanned, and connection will be re-established as per preferences as needed.

import uasyncio as asyncio
import logging
from wifi_manager import WifiManager

logging.basicConfig(level=logging.WARNING)
WifiManager.start_managing()
asyncio.get_event_loop().run_forever()

Contribution

Found a bug, or want a feature? open an issue.

If you want to contribute, create a pull request.

System flow

System flow

micropython-wifimanager's People

Contributors

ibobik avatar mitchins 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  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

micropython-wifimanager's Issues

Webrepl is accessible everywhere if used for AP

If I have webrepl enabled for access point it will make it available even for other networks.

My config:

{
	"schema": 2,
	"known_networks": [
		{
			"ssid": "xxxxxx",
			"password": "xxxxxx",
			"enables_webrepl": false
		},
		{
			"ssid": "xxxxxx",
			"password": "xxxxxx",
			"enables_webrepl": false
		}
	],
	"access_point": {
		"config": {
			"essid": "xxxxxx",
			"channel": 11,
			"hidden": false,
			"password": "xxxxxx"
		},
		"enables_webrepl": true,
		"start_policy": "always"
	}
}

This is like security bug for me.

Feature Request: Execute callback function when wifi connection state changes

It would be nice to provide a callback hook when wifi connection state changes so other modules can be notified. For instance, if wifi disconnects, then I can blink an LED to let the user now the device is reconnecting. Right now I would have to create my own task that polls wlan.isconnected() repeatedly.

Here's what the API could look like:

manager = WifiManager()
manager.add_connection_handler(handle_wifi_connection)


def handle_wifi_connection(is_connected):
    if is_connected:
        status_led.on()
    else:
        status_led.blink()

I'm not sure if this project is still active. If so, I'd be more than willing to submit a PR for this feature. Just give me a ๐Ÿ‘ from one of the maintainers and I'll make it happen.

upip install fails

I'm unable to install micropython-wifimanger via upip on my ESP8266.

>>> upip.install('micropython-wifimanager')
Installing to: /lib/
Queue: ['micropython-wifimanager']
https://micropython.org/pi/micropython-wifimanager/json
https://pypi.org/pypi/micropython-wifimanager/json
Error installing 'micropython-wifimanager': , packages may be partially installed

Same is on native linux

$ micropython -m upip install --debug micropython-wifimanager
Installing to: /home/asdf/snap/micropython/80/.micropython/lib/
Queue: ['micropython-wifimanager']
https://micropython.org/pi/micropython-wifimanager/json
Warning: micropython.org SSL certificate is not validated
https://pypi.org/pypi/micropython-wifimanager/json
Error installing 'micropython-wifimanager': , packages may be partially installed

It seems that something is wrong with the hosting of the package itself, because if I try to access the link from the logs (https://micropython.org/pi/micropython-wifimanager/json) in my browser, I get "404 Not found" error.

WiFiManager Generates a Traceback/OSError: [Errno 5] EIO on TinyPico

I've tried WiFiManager with with MicroPython builds:

tinypico-idf3-20191220-v1.12
tinypico-idf3-20200223-v1.12-195-gb16990425

Just running the bare main.py included in WiFiManager-master.

The traceback occurs write after the SSID and password check succeeds. The wifi.dat is not saved.

Errors:
Connected. Network config: ('192.168.4.89', '255.255.255.0', '192.168.4.254', '192.168.4.254')
Traceback (most recent call last):
File "main.py", line 4, in
File "wifimgr.py", line 60, in get_connection
File "wifimgr.py", line 306, in start
File "wifimgr.py", line 213, in handle_configure
File "wifimgr.py", line 112, in send_response
File "wifimgr.py", line 103, in send_header
OSError: [Errno 5] EIO

Can not install by upip

In just installed and connected ESP8266 4MB:

>>> import network
>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.active(True)
#6 ets_task(4020f474, 28, 3fffa018, 10)
>>> sta_if.connect('xxx', 'xxx')
>>> sta_if.ifconfig()
('192.168.0.192', '255.255.255.0', '192.168.0.1', '213.46.172.37')
>>> import upip
>>> upip.install('micropython-wifimanager')
Installing to: /lib/
Warning: pypi.org SSL certificate is not validated
Installing micropython-wifimanager 0.3.3 from https://files.pythonhosted.org/packages/ab/bf/5f896441ca23c794fc7011f5429a04b44018a686789d592cf8d9911afd1a/micropython-wifimanager-0.3.3.tar.gz
Error installing 'micropython-wifimanager': [Errno 22] EINVAL, packages may be partially installed
>>> 

Feature Request: Provide a REST API to interact with config file

It would be nice to have a REST API to interact with the config file that way developers could create a UI for users to bootstrap the device. Actually, a wrapper class that handles CRUD operations on the config file would support a REST API as well as a traditional web interface. Something like:

GET /wifi/known_networks
GET /wifi/access_point
wifi_config = WifiConfig()
wifi_config.known_networks.append({
    "ssid": "my_access_point",
    "password": "my_access_point_password",
    "enables_webrepl": False,
})
wifi_config.save()

I'm not sure if this project is still active. If so, I'd be more than willing to submit a PR for this feature. Just give me a ๐Ÿ‘
from one of the maintainers and I'll make it happen.

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.