Add gpio script for ap mode
authorPeng Li <seudut@gmail.com>
Mon, 27 Aug 2018 17:35:50 +0000 (01:35 +0800)
committerPeng Li <seudut@gmail.com>
Mon, 27 Aug 2018 17:35:50 +0000 (01:35 +0800)
script/boot_ap_mode.py [new file with mode: 0755]
views/main.tpl
views/test.pl [deleted file]
views/test.tpl [deleted file]
web.py

diff --git a/script/boot_ap_mode.py b/script/boot_ap_mode.py
new file mode 100755 (executable)
index 0000000..f715aeb
--- /dev/null
@@ -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)
+
+
index c0d32f1..fde481a 100644 (file)
@@ -10,11 +10,13 @@ IP Addr Info: <br>
 </textarea>
 <form action="/main" method="post">
 <br>
-Current Mode {{mode}}
-<input type="checkbox" name=
-    Scan and Select the WiFI to connect to:<br>
+Current Mode {{mode}} <br>
+Scan and Select the WiFI to connect to:<br>
     <select name='select'>
         % for ssid in ssids:
+        % if mode == 'AP':
+            <option value="----" selected>{{ssid}}</option>
+        % end
         % if ssid == usedSsid:
             <option value={{ssid}} selected>{{ssid}}</option>
         % else:
diff --git a/views/test.pl b/views/test.pl
deleted file mode 100644 (file)
index 176d989..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-%if name == 'World':
-    <h1>Hello {{name}}!</h1>
-    <p>This is a test.</p>
-%else:
-    <h1>Hello {{name.title()}}!</h1>
-    <p>How are you?</p>
-%end
diff --git a/views/test.tpl b/views/test.tpl
deleted file mode 100644 (file)
index 754c744..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<html>
-<body>
-<div id='Network Config' style="text-align:center;">
-<p>Login<p>
-    <form action='/mm' method='post'>
-    Username: <input name="username" type="password" /><br>
-    Password: <input name="password" type="password" />
-    </form>
-</div>
-
-<div id='Tracker++ Config'>
-    <form action='/mm' method='post'>
-    Username: <input name="username" type="password" />
-    Password: <input name="password" type="password" />
-    </form>
-</div>
-<p>This is atest </p>
-</body>
-</html>
diff --git a/web.py b/web.py
index f75c5c4..180ed3e 100644 (file)
--- 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(),