f715aeb40278b6cf89b51fb9304f435cf3c31fce
[networtool-web.git] / script / boot_ap_mode.py
1 #!/usr/bin/env python2
2 from gpiozero import Button
3 import subprocess
4 import os
5
6 # https://gpiozero.readthedocs.io/en/stable/recipes.html#pin-numbering
7 # https://www.raspberrypi.org/documentation/usage/gpio/ 
8
9 # Add this line in /etc/rc.local
10 # /usr/local/networktool-web/script/boot_ap_mode.py 2>&1 > /tmp/boot_ap_mode.txt
11
12 # This script is used to boot with AP mode or WiFi mode.
13 # Run this in rc.local. When boot, it check the GPIO 21, if it is Low level (connected to Ground)
14 # Then it starts with AP mode
15
16 DIR = os.path.dirname(os.path.realpath(__file__))
17
18 button = Button(21)
19 if button.is_pressed:
20     print 'button is pressed, switch to ap mode\n'
21     subprocess.check_call(DIR + '/startHostapd.sh', shell=True)
22
23