Skip to content

Commit

Permalink
Merge pull request #2 from brainelectronics/feature/improve-html-pages
Browse files Browse the repository at this point in the history
Improve html pages UI
  • Loading branch information
brainelectronics authored Feb 16, 2022
2 parents 642c351 + 8d0cdfc commit 62b54cb
Show file tree
Hide file tree
Showing 23 changed files with 1,017 additions and 567 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,38 @@ cp SOURCE_FILE_NAME /pyboard/NEW_FILE_NAME
Copying '/Users/Jones/Downloads/MicroPython/ESP-WiFi-Manager/wifi_manager.py' to '/pyboard/wifi_manager.py' ...
```
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/
# around 24kB compared to uncompressed 120kB

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

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

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

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

cp boot.py /pyboard
cp main.py /pyboard
cp wifi_manager.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
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial [`WiFi Manager`](wifi_manager.py) implementation
- Micropython [`boot`](boot.py) and [`main`](main.py) files
- [`README`](README.md) and [`requirements.txt`](requirements.txt) files
- Compressed version of
[`bootstrap.min.css`](simulation/static/css/bootstrap.min.css) and
[`bootstrap.min.js`](simulation/static/js/bootstrap.min.js)

#### Simulation
- [`Simulation README`](simulation/README.md) file
Expand All @@ -52,6 +55,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[network station and client](simulation/src/wifi_helper/network.py)
- Bash script to prepare all folders for a unittest coverage report
- Unittests for all modules and fakes
- Render list of selectable networks in Python and provide result via API
- `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
Expand Down
22 changes: 11 additions & 11 deletions simulation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ On Windows the package `pycryptodome>=3.14.0,<4` shall be used instead of

Simulation webpages use [bootstrap 3.4][ref-bootstrap-34].

## Usage

Run the simulation of the ESP WiFi Manager **after** activating the virtual
environment of the [Setup section](#setup)

```bash
sh run.sh
```

Open [`http://127.0.0.1:5000/`](http://127.0.0.1:5000/){:target="_blank"} in a browser

## Unittests

### General
Expand Down Expand Up @@ -170,17 +181,6 @@ Test [`wifi manager`][ref-wifi-manager-test] implementation.
nose2 --config tests/unittest.cfg -v tests.test_wifi_manager.TestWiFiManager
```

## Usage

Run the simulation of the ESP WiFi Manager **after** activating the virtual
environment of the [Setup section](#setup)

```bash
sh run.sh
```

Open [`http://127.0.0.1:5000/`](http://127.0.0.1:5000/){:target="_blank"} in a browser

<!-- Links -->
<!-- Generic -->
[ref-bootstrap-34]: https://getbootstrap.com/docs/3.4/getting-started/#download
Expand Down
2 changes: 1 addition & 1 deletion simulation/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ flask>=2.0.2,<3
jinja2>=3.0.2,<4
PyYAML>=5.4.1,<6
nose2>=0.10.0,<1
pycrypto>=2.6.1,<3
netifaces>=0.11.0,<1
pycrypto>=2.6.1,<3
2 changes: 1 addition & 1 deletion simulation/src/generic_helper/generic_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import random
import sys

from typing import (Optional, Union)
from typing import Optional, Union


class GenericHelper(object):
Expand Down
1 change: 0 additions & 1 deletion simulation/src/led_helper/led_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def fade(self, delay_ms: int = 50, pixel_amount: int = -1) -> None:
self.fade_pixel_amount = pixel_amount
self.fading = True

# def _fade(self, delay_ms: int, pixel_amount: int, lock: lock) -> None:
def _fade(self, delay_ms: int, pixel_amount: int, lock: int) -> None:
"""
Internal Neopixel fading thread content.
Expand Down
6 changes: 5 additions & 1 deletion simulation/src/path_helper/path_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""Provide unavailable path functions in MicroPython"""
"""
Path Helper
Provide unavailable path functions for Micropython boards
"""

# import os
from pathlib import Path
Expand Down
6 changes: 5 additions & 1 deletion simulation/src/time_helper/time_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""try to sync and set the internal clock (RTC) with NTP server time"""
"""
Time Helper
Sync and set internal clock (RTC) with NTP server time
"""

from machine import RTC
# import ntptime
Expand Down
10 changes: 3 additions & 7 deletions simulation/src/wifi_helper/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def _scan_mac() -> List[dict]:
scan_result = subprocess.check_output(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '--scan'])

if len(scan_result) == 0:
print('### Check WiFi to be active ###')
print('Returning dummy data')
return NetworkHelper._dummy_data()

scan_result = [ele.decode('ascii') for ele in scan_result.splitlines()]
Expand Down Expand Up @@ -188,17 +186,14 @@ def _scan_windows() -> List[dict]:
try:
scan_result = subprocess.check_output(['netsh', 'wlan', 'show', 'networks', 'mode=bssid'])
except Exception as e:
print('Failed to scan due to this error: {}'.format(e))
print('### Check WiFi to be active ###')
print('Returning dummy data')
# print('Failed to scan due to this error: {}'.format(e))
return NetworkHelper._dummy_data()

# netsh call returns report in local language, try to decode it
try:
scan_result = [ele.decode('cp850').lstrip() for ele in scan_result.splitlines()]
except Exception as e:
print('Failed to decode scan data due to this error: {}'.format(e))
print('Returning dummy data')
# print('Failed to decode scan data due to this error: {}'.format(e))
return NetworkHelper._dummy_data()

# [
Expand Down Expand Up @@ -366,6 +361,7 @@ def _dummy_data() -> List[dict]:
'hidden': False
}
]
# print('Returning dummy data')

return nets

Expand Down
9 changes: 7 additions & 2 deletions simulation/src/wifi_helper/wifi_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""connect to specified network(s) or create an accesspoint"""
"""
WiFi Helper
Connect to specified network(s) or create an accesspoint
"""

# import ubinascii
import json
Expand Down Expand Up @@ -341,7 +345,8 @@ def scan_networks(self) -> None:
try:
net['authmode'] = self.auth_modes[net['authmode']]
except KeyError:
print('{} is unknown authmode'.format(net['authmode']))
# print('{} is unknown authmode'.format(net['authmode']))
pass
except Exception:
pass
if 'bssid' in net:
Expand Down
Loading

0 comments on commit 62b54cb

Please sign in to comment.