From 480bfdd3cbb50749f8f22eabb75c6cc2d6c467f6 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Tue, 28 Aug 2018 01:35:50 +0800 Subject: [PATCH] Add gpio script for ap mode --- script/boot_ap_mode.py | 23 +++++++++++++++++++++++ views/main.tpl | 8 +++++--- views/test.pl | 7 ------- views/test.tpl | 19 ------------------- web.py | 7 ++++--- 5 files changed, 32 insertions(+), 32 deletions(-) create mode 100755 script/boot_ap_mode.py delete mode 100644 views/test.pl delete mode 100644 views/test.tpl diff --git a/script/boot_ap_mode.py b/script/boot_ap_mode.py new file mode 100755 index 0000000..f715aeb --- /dev/null +++ b/script/boot_ap_mode.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python2 +from gpiozero import Button +import subprocess +import os + +# https://gpiozero.readthedocs.io/en/stable/recipes.html#pin-numbering +# https://www.raspberrypi.org/documentation/usage/gpio/ + +# Add this line in /etc/rc.local +# /usr/local/networktool-web/script/boot_ap_mode.py 2>&1 > /tmp/boot_ap_mode.txt + +# This script is used to boot with AP mode or WiFi mode. +# Run this in rc.local. When boot, it check the GPIO 21, if it is Low level (connected to Ground) +# Then it starts with AP mode + +DIR = os.path.dirname(os.path.realpath(__file__)) + +button = Button(21) +if button.is_pressed: + print 'button is pressed, switch to ap mode\n' + subprocess.check_call(DIR + '/startHostapd.sh', shell=True) + + diff --git a/views/main.tpl b/views/main.tpl index c0d32f1..fde481a 100644 --- a/views/main.tpl +++ b/views/main.tpl @@ -10,11 +10,13 @@ IP Addr Info:

-Current Mode {{mode}} - +Current Mode {{mode}}
+Scan and Select the WiFI to connect to:

- Password: -
- - -
-
- Username: - Password: -
-
-

This is atest

- - diff --git a/web.py b/web.py index f75c5c4..180ed3e 100644 --- a/web.py +++ b/web.py @@ -7,6 +7,8 @@ import subprocess DIR = os.path.dirname(os.path.realpath(__file__)) CONF = '/usr/local/trackerpp/config/trackerpp.conf' SERVICE = 'trackerpp.service' +USERNAME = 'admin' +PASSWORD = 'admin123' TEMPLATE_PATH.insert(0, DIR + '/views/') @@ -22,7 +24,7 @@ def getIpAddr(): # return AP or def getCurrentMode(): - return subprocess.check_output("iw dev | grep type | awk '{print $2}'", shell=True).strip() + return subprocess.check_output("iw dev wlan0 info | grep type | awk '{print $2}'", shell=True).strip() def isAPmode(): return getCurrentMode() == 'AP' @@ -87,8 +89,7 @@ def login(): return template('login.tpl', username="username", password="password") def check_login(username, password): - return True - #return username == 'admin' and password == 'admin123' + return username == USERNAME and password == PASSWORD form_dict = {'ipaddr': getIpAddr(), 'ssids': getSSIDs(), -- 2.11.0