Fast boot to python script without networking? Topic is solved

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
NJS

Re: Fast boot to python script without networking?

Post by NJS »

Yes, I have installed some python and camera-related software using apt-get, however, to be clear, I have no reason to think hostapd is currently installed I was just asking about it because of your prior post:
To enable/start:
In /etc/network/interfaces , uncomment:
allow-hotplug wlan0

Reload systemd
systemctl daemon-reload

Start hostapd
systemctl restart hostapd
Thanks again.
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: Fast boot to python script without networking?

Post by Fourdee »

NJS wrote:Yes, I have installed some python and camera-related software using apt-get, however, to be clear, I have no reason to think hostapd is currently installed I was just asking about it because of your prior post:
Ah yes, apologies.

I assumed you used dietpi-software to install WiFi hotspot :)
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
NJS

Re: Fast boot to python script without networking?

Post by NJS »

I'm finally returning to this project after several months hiatus! Here's how I ended up bringing up and taking down WLAN from within my python script...

First, I edited /etc/network/interfaces to comment out everything but the following:

Code: Select all

# Local
auto lo
iface lo inet loopback
Then to bring up the WLAN with static IP from within python:

Code: Select all

proc = subprocess.Popen("sudo ip link set wlan0 up", shell=True, stdout=subprocess.PIPE)
proc.wait()
proc = subprocess.Popen("sudo iwconfig wlan0 txpower auto", shell=True, stdout=subprocess.PIPE)
proc.wait()
proc = subprocess.Popen("sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf", shell=True, stdout=subprocess.PIPE)
proc.wait()
proc = subprocess.Popen("sudo ip addr add 192.168.15.123/24 broadcast 192.168.15.255 dev wlan0", shell=True, stdout=subprocess.PIPE)
proc.wait()
proc = subprocess.Popen("sudo ip route add default via 192.168.15.1", shell=True, stdout=subprocess.PIPE)


Or, to use DHCP, replace the last two "ip" calls with:

Code: Select all

proc = subprocess.Popen("sudo dhclient -v wlan0", shell=True, stdout=subprocess.PIPE)
Note that WLAN details (e.g. SSID and PSK) are defined in /etc/wpa_supplicant/wpa_supplicant.conf. Alternatively this should work:

Code: Select all

wpa_supplicant -B -i wlan0-c <(wpa_passphrase MYSSID passphrase)
making use of wpa_passphrase, a command line tool which generates the minimal configuration needed by wpa_supplicant.

Also "sudo" should not be needed anywhere as long as python script is running as root, but I included to eliminate that requirement (although apparently the following wouldn't work for non-root user due to process substitution:

Code: Select all

sudo wpa_supplicant -B -i wlan0-c <(wpa_passphrase MYSSID passphrase)
)

To take the network down from within the python script I used the following:

Code: Select all

proc = subprocess.Popen("sudo iwconfig wlan0 txpower off ", shell=True, stdout=subprocess.PIPE)
proc.wait()
proc = subprocess.Popen("sudo ip link set wlan0 down", shell=True, stdout=subprocess.PIPE)
Next I need to get NTP to run after bringing up the network. For some reason, the following seems to hang:

Code: Select all

proc = subprocess.Popen("ntpd -g -q", shell=True, stdout=subprocess.PIPE)
Comments and/or suggestions appreciated![/b]

For more info see: https://wiki.archlinux.org/index.php/WPA_supplicant ,
https://wiki.archlinux.org/index.php/Ne ... figuration and
https://wiki.archlinux.org/index.php/Wi ... figuration
Post Reply