Add gpio script for ap mode
[networtool-web.git] / script / boot_ap_mode.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)
+
+