One problem I found when playing with my Raspberry PI3 (running Raspbian Jessie), is that the WiFi would drop after a certain amount of inactivity. This was problematic at VMUG Meetings, and due to lack of having a screen to connect, I was forced to power-cycle the unit to get it back online. After doing some googling, I found the built-in WiFi for the Raspberry PI 3 had some Power Management features, which were enabled by default.
You can check the status by running the follow command:
sudo iwconfig wlan
I found a simple command to disable the power management features, however the command only lasted until the next reboot and then went back to the default setting. The command is below
sudo iwconfig wlan0 power off
After doing some investigating, I came across this blog post on how to run a script at startup. This enabled me to put the above command into a script and run it at startup! http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/
The steps were simple.
2. Run the command below to create a script :
sudo nano script.sh
3. Enter the command above into the new script.sh file. Don’t forget to include the first line though, or it won’t run properly. You also don’t need SUDO before iwconfig here, as the script is being run at an elevated level already. 🙂
#!/bin/sh - iwconfig wlan0 power off
4. Next, we have to create a configuration file (aka a unit file) that tells systemd what we want to do when…
sudo nano /lib/systemd/system/myscript.service
5. Enter the text below into the text editor
[Unit] Description=My Script Service After=multi-user.target [Service] Type=idle ExecStart=/home/pi/script.sh [Install] WantedBy=multi-user.target
6. The permissions on the unit file need to be set to 644.
sudo chmod 644 /lib/systemd/system/myscript.service
ls –l /lib/systemd/system/myscript*
8. Now that the unit file has been defined, we can tell systemd to start it during the boot sequence.
sudo systemctl daemon-reload
sudo systemctl enable myscript.service
10. Finally, REBOOT!
11. Once your PI is back online, login and check the status now…
sudo iwconfig wlan0
Ben Liebowitz, VCP, vExpert
NJ VMUG Leader