Sunday, January 31, 2016

Raspberry Pi Tips and Tricks

Rename Raspi

Information is taken from:

At the terminal, type the following command to open the hosts file:
sudo nano /etc/hosts
Your hosts file will look like so:
Leave all of the entries alone except for the very last entry labeled with the hostname “raspberrypi“. This is the only line you want to edit. Replace “raspberrypi” with whatever hostname you desire. We replaced it on our device with “weatherstation“. Press CTRL+X to close the editor; agree to overwrite the existing file and save it.
Back at the terminal, type the following command to open the hostname file:
sudo nano /etc/hostname
This file only contains your current hostname:

Replace the default “raspberrypi” with the same hostname you put in the previous step (e.g. “weatherstation“). Again, press CTRL+X to close the editor, agree to overwrite the existing file and save it.
Finally, we need to commit the changes to the system and reboot the system for the changes to take effect. At the terminal, enter the following command to commit the changes:
sudo /etc/init.d/
Follow that command with:
sudo reboot

Change Password

Information taken from:

Enter the following command once logged into the raspi:


Then it will prompt your to:

  1. enter your old password
  2. enter new password
  3. enter new password

Static IP Address

Multiple Wifi Networks

Information was taken from:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
This file had some text in it already, which I left untouched. Below that, add:


Once you have edited and saved your wpa_supplicant.conf file, you can go about editing the /etc/network/interfaces file. Again, open this in your favorite text editor.
sudo nano /etc/network/interfaces

Some text was already in here, but I modified the file to look like:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet dhcp

pre-up wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B
post-down killall -q wpa_supplicant
post-down rm /var/run/wpa_supplicant/wlan0

iface my_home inet dhcp
#address [ip address for home network]
#netmask [mask for home network]
#gateway [gateway address for home network]

iface parents_home inet dhcp
#address [ip address for phone network]
#netmask [mask for phone network]
#gateway [gateway address for phone network]

Once you have edited and saved /etc/network/interfaces, you need to restart the network service for the networking configuration to take effect.
sudo service networking restart

Schedule Reboots/Tasks

Information was taken from:

Enter this command:
sudo crontab -e

Add this to the end of the file...

00 03 * * * sudo reboot

This will reboot at 3am each day.

Monitor Pi System Processes

To install htop simply use:
sudo apt-get install htop

Once installed you can start it using:

Power Saving Tips

Information was relayed from:

Tip 5 Turn off video output (based on comment by Antonio David Alarcón Doval)
This tip has been suggested by many people. If your system is headless (no video output) you can turn off the HDMI port with:
sudo /opt/vc/bin/tvservice -o
to turn it back on:
sudo /opt/vc/bin/tvservice -p
This command will save you around 20-30mA. 

No comments:

Post a Comment