Skip to content

Commit

Permalink
Merge pull request #6 from brainelectronics/feature/create-upip-lib
Browse files Browse the repository at this point in the history
Create upip lib
  • Loading branch information
brainelectronics authored Feb 25, 2022
2 parents 2ce43a2 + 7224297 commit 8e20a43
Show file tree
Hide file tree
Showing 35 changed files with 427 additions and 1,647 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
*.o
*/R.py

.vagrant/

# project specific files
simulation/wifi-secure.json
.idea
simulation/reports/*
.rshell-setup
configs/*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "helpers"]
path = helpers
url = [email protected]:brainelectronics/micropython-modules.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 brainelectronics and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion LICENSE.md

This file was deleted.

163 changes: 70 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ESP WiFi Manager

Simple Flask style Micropython Server running on an ESP32

MicroPython WiFi Manager to configure and connect to networks

-----------------------

Expand Down Expand Up @@ -52,140 +51,118 @@ is no external PRSAM only the non SPIRAM version is working.

### Upload files to board

#### rshell
#### Install package with pip

Open the remote shell with the following command. Additionally use `-b 115200`
in case no CP210x is used but a CH34x.
Connect to a network

```bash
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
```python
import network
station = network.WLAN(network.STA_IF)
station.connect('SSID', 'PASSWORD')
station.isconnected()
```

##### Setup check

Check the board config with this simple `boards` call inside the rshell. The
result will look similar to this after the connection
and install this lib on the MicroPython device like this

```bash
Using buffer-size of 32
Connecting to /dev/tty.SLAB_USBtoUART (buffer-size 32)...
Trying to connect to REPL connected
Retrieving sysname ... esp32
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /boot.py/ /helpers/ /lib/ /main.py/ /templates/ /wifi-secure.json/ /winbond.py/
Setting time ... Oct 11, 2021 13:15:24
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/Users/Jones/Downloads/MicroPython/ESP-Webserver-Picoweb> boards
pyboard @ /dev/tty.SLAB_USBtoUART connected Epoch: 2000 Dirs: /boot.py /static /templates /wifi_manager.py /pyboard/boot.py /pyboard/static /pyboard/templates /pyboard/wifi_manager.py
```python
import upip
# may use the latest test version of it, by adding test.pypi.org as the first
# location to search for the package
# upip.index_urls = ["https://test.pypi.org/pypi", "https://micropython.org/pi", "https://pypi.org/pypi"]
upip.install('micropython-esp-wifi-manager')
# its dependencies will be installed alongside

# if test.pypi.org is added to the index urls, required depencendies won't be
# installed if they are not available from test.pypi.org, may install them
# manually
# upip.index_urls = ["https://micropython.org/pi", "https://pypi.org/pypi"]
# upip.install('picoweb')
# upip.install('micropython-ulogging')
# upip.install('utemplate')
```

##### Download files (with script)
#### Manually

Files can be copied to the device with the following command
##### Upload files to board

```bash
cp SOURCE_FILE_NAME /pyboard
Copy the module(s) to the MicroPython board and import them as shown below
using [Remote MicroPython shell][ref-remote-upy-shell]

# optional copy it as another file name
cp SOURCE_FILE_NAME /pyboard/NEW_FILE_NAME
```
Open the remote shell with the following command. Additionally use `-b 115200`
in case no CP210x is used but a CH34x.

```bash
/Users/Jones/Downloads/MicroPython/ESP-WiFi-Manager/> cp wifi_manager.py /pyboard
Copying '/Users/Jones/Downloads/MicroPython/ESP-WiFi-Manager/wifi_manager.py' to '/pyboard/wifi_manager.py' ...
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
```

Create compressed CSS and JS files as described in the
[simulation static files README](simulation/static) to save disk space on the
device and increase the performance (webpages are loading faster)

```bash
mkdir /pyboard/static/
cp simulation/static/css/*.gz /pyboard/static/
mkdir /pyboard/lib/
mkdir /pyboard/lib/wifi_manager/
mkdir /pyboard/lib/wifi_manager/static/
mkdir /pyboard/lib/wifi_manager/static/css
cp static/css/*.gz /pyboard/lib/wifi_manager/static/css
# around 24kB compared to uncompressed 120kB

# optional, not used so far
# mkdir /pyboard/static/
# cp simulation/static/js/*.gz /pyboard/static/
# mkdir /pyboard/lib/wifi_manager/static/js
# cp static/js/*.gz /pyboard/lib/wifi_manager/static/js
# around 12kB compared to uncompressed 40kB

mkdir /pyboard/templates
cp templates/* /pyboard/templates
mkdir /pyboard/lib/wifi_manager/templates/
cp templates/* /pyboard/lib/wifi_manager/templates/
# around 20kB

mkdir /pyboard/helpers
cp helpers/*.py /pyboard/helpers
# around 64kB

mkdir /pyboard/primitives
cp primitives/*.py /pyboard/primitives
# around 8kB

mkdir /pyboard/lib
cp -r lib/* /pyboard/lib
# around 72kB

cp wifi_manager.py /pyboard
cp wifi_manager/wifi_manager.py /pyboard/lib/wifi_manager/
cp main.py /pyboard
cp boot.py /pyboard
# around 40kB
```

##### Open REPL in rshell
Call `repl` in the rshell. Use CTRL+X to leave the repl or CTRL+D for a soft
reboot of the device
### Install Micropython Packages
Restart ESP device and open the printed IP address in your browser
##### Install additional MicroPython packages

Close all connection, and start REPL of uPyCraft or other serial connection.
As this package has not been installed with `upip` additional modules are
required, which are not part of this repo. To install these modules on the
device, connect to a network and install them via `upip` as follows

```python
import upip

upip.install('picoweb')
upip.install('utemplate')
upip.install('micropython-ulogging')
upip.install('micropython-brainelectronics-helper')
```

<!--
## Templates
## Usage

If a template `.tpl` is updated on the device, the old and outdated `_tpl.py`
file shall be deleted.
After all files have been transfered or installed open a REPL to the device.

Its content might be outdated with respect to the input parameters.
The device will try to load and connect to the configured networks based on an
encrypted JSON file.

```python
# Autogenerated file
def render(req, mytime):
yield """
<html>
Request path: '"""
yield str(req.path)
yield """'<br>
<table border=\"1\">
"""
for i in range(5):
yield """
<tr><td> """
yield str(i)
yield """ </td><td> """
yield str("%2d" % i ** 2)
yield """ </td></tr>
"""
yield """
</table>
Time: '"""
yield str(mytime)
yield """'<br>
</html>
"""
```
-->
In case no network has been configured or no connection could be established
to any of the configured networks within the timeout of each 5 seconds an
AccessPoint at `192.168.4.1` is created.

A simple Picoweb webserver is hosting the webpages to connect to new networks,
to remove already configured networks from the list of connections to
establish and to get the latest available networks as JSON.

This is a list of available webpages

| URL | Description |
|-----|-------------|
| `/` | Root index page, to choose from the available pages |
| `/select` | Select and configure a network |
| `/configure` | Manage already configured networks |
| `/scan_result` | JSON of available networks |

To leave from the Webinterface, just press CTRL+C and wait until all threads
finish running. This takes around 1 second. The device will return to its REPL

<!-- Links -->
[ref-esptool]: https://github.com/espressif/esptool
Expand Down
5 changes: 3 additions & 2 deletions boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import time

# custom packages
from helpers.led_helper import Led
from be_helpers.led_helper import Led


# set clock speed to 240MHz instead of default 160MHz
Expand All @@ -27,8 +27,9 @@
station = network.WLAN(network.STA_IF)
if station.active() and station.isconnected():
station.disconnect()
time.sleep(1)
station.active(False)
time.sleep_ms(1000)
time.sleep(1)
station.active(True)

led.turn_off()
Expand Down
38 changes: 37 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-->

## [Unreleased]
## [1.0.0] - 2022-02-25
### Added
- [`setup.py`](setup.py) and [`sdist_upip.py`](sdist_upip.py) taken from
[pfalcon's picoweb repo][ref-pfalcon-picoweb-sdist-upip] and PEP8 improved
- [`MIT License`](LICENSE)
- [`version.py`](wifi_manager/version.py) storing current library version

### Changed
- Moved all MicroPython WiFi manager files into folder named
[`wifi_manager`](wifi_manager)
- Update [`README`](README.md) usage description of MicroPython lib deploy to
[PyPi][ref-pypi]
- Usage examples in [`README`](README.md) updated with new import path
- Moved static web files from [`simulation/static`](simulation/static/) to
[`static`](static)
- Adjust path to static folder in
[WiFi Manager Simulation](simulation/src/wifi_manager/wifi_manager.py) from
[`simulation/static`](simulation/static/) to [`static`](static)
- Update [WiFi Manager simulation](simulation/src/wifi_manager/wifi_manager.py)
to latest MicroPython implementation
- Update [`boot`](boot.py) and [`main`](main.py) files to use `be_helpers`

### Removed
- MicroPython helpers module no longer used, replaced by pip install
requirement
- Lib of dependency modules no longer used
- Primitives folder no longer used, files are part of
[brainelectronics MicroPython helpers][ref-be-micropython-module]
- Unused `style.css` from [`static`](static)

## [0.1.1] - 2022-02-19
### Fixed
- Sleep after adding the latest found networks to the asyncio message, not
Expand Down Expand Up @@ -65,6 +95,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `sendfile` function implemented in same way as on Micropythons PicoWeb

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/Micropython-ESP-WiFi-Manager/compare/0.1.0...develop
[Unreleased]: https://github.com/brainelectronics/Micropython-ESP-WiFi-Manager/compare/1.0.0...develop

[1.0.0]: https://github.com/brainelectronics/Micropython-ESP-WiFi-Manager//tree/1.0.0
[0.1.1]: https://github.com/brainelectronics/Micropython-ESP-WiFi-Manager//tree/0.1.1
[0.1.0]: https://github.com/brainelectronics/Micropython-ESP-WiFi-Manager//tree/0.1.0

[ref-pypi]: https://pypi.org/
[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py
[ref-be-micropython-module]: https://github.com/brainelectronics/micropython-modules/tree/1.1.0
1 change: 0 additions & 1 deletion helpers
Submodule helpers deleted from 6205cd
1 change: 0 additions & 1 deletion lib/@PaxHeader

This file was deleted.

Loading

0 comments on commit 8e20a43

Please sign in to comment.