2017-08-19, 08:24 PM
Sorry, I don't mean to bombard folks with questions. I'm just trying to get everything setup.
To conserve power I am trying to create a button that will turn off and on the wifiAP.
Someone with python 3 knowledge showed me how to and created this code:
However it seems to always think the AP is off and thus the button always tries to turn it on. I assume this is something to do with how OpenPlotter turns on AP. Though I am not ruling out a different error in the code. Any help to get this working would be great.
To conserve power I am trying to create a button that will turn off and on the wifiAP.
Someone with python 3 knowledge showed me how to and created this code:
Code:
import subprocess
from gpiozero import LED, Button
from signal import pause
led1 = LED(18)
button1 = Button(23)
def wifionoff():
retcode = subprocess.call([`sudo`, `systemctl`, `-q`, `is-active`, `hostap`])
if retcode == 0:
# switch LED off
led1.off()
# switch wifi off
subprocess.call([`sudo`, `systemctl`, `stop`, `isc-dhcp-server`])
subprocess.call([`sudo`, `systemctl`, `stop`, `hostap`])
subprocess.call([`sudo`, `ifdown`, `wlan0`])
subprocess.call([`sudo`, `rfkill`, `block`, `0`])
else:
# switch wifi on
subprocess.call([`sudo`, `rfkill`, `unblock`, `0`])
subprocess.call([`sudo`, `ifup`, `wlan0`])
subprocess.call([`sudo`, `systemctl`, `start`, `hostap`])
subprocess.call([`sudo`, `systemctl`, `start`, `isc-dhcp-server`])
# switch LED on
led1.on()
button1.when_pressed = wifionoff
pause()
However it seems to always think the AP is off and thus the button always tries to turn it on. I assume this is something to do with how OpenPlotter turns on AP. Though I am not ruling out a different error in the code. Any help to get this working would be great.