5 Useful Ways to Use Your Raspberry Pi

Hello Habr.

Almost everyone has a Raspberry Pi at home, and I would venture to guess that many have it lying around idle. But Raspberry is not only a valuable fur, but also a quite powerful fanless computer with Linux. Today we will look at the useful features of the Raspberry Pi, for which you do not have to write code at all.
5 Useful Ways to Use Your Raspberry Pi
For those who are interested, the details are under the cut. The article is intended for beginners.

Note: This article is intended for beginners who have at least a basic understanding of what an IP address is, how to SSH into a Raspberry Pi using putty or any other terminal, and how to edit files with the nano editor. As an experiment, this time I will not “load” readers with Python code, there will be no programming at all. For all of the following, only the command line will suffice. How much such a format is in demand, I will look at the estimates of the text.

Of course, I will not consider very obvious things like an FTP server or network balls. Below I tried to highlight something more or less useful and original.

Before we install anything, an important council: the right power supply (preferably a branded 2.5A one, rather than a noname phone charger) and a heatsink for the processor are extremely important for the stable operation of the Raspberry Pi. Without this, Raspberry may freeze, file copy errors may appear, etc. The insidiousness of such errors is that they appear only occasionally, for example, during peak CPU load or when large files are being written to the SD card.

Before installing any components, it is advisable to update the system, otherwise the old addresses for the apt command may not work:

sudo apt-get update

Now you can start installing and configuring.

1. WiFi hotspot

Raspberry Pi is easy to turn into a wireless access point, and you don’t have to buy anything, WiFi is already on board. To do this, you need to install 2 components: hostapd (Host access point daemon, access point service) and dnsmasq (DNS / DHCP server).

Install dnsmasq and hostapd:

sudo apt-get install dnsmasq hostapd

Set the static IP address that the Raspberry Pi will have on the WiFi network. To do this, edit the dhcpcd.conf file by entering the command sudo nano /etc/dhcpcd.conf. You need to add the following lines to the file:

interface wlan0
  static ip_address=198.51.100.100/24
  nohook wpa_supplicant

As you can see, in the WiFi network, our Raspberry Pi will have the address 198.51.100.100 (this is important to remember if some server is running on it, the address of which will need to be entered in the browser).

Next, we must activate IP forwarding, for which we execute the command sudo nano /etc/sysctl.conf and uncomment the line net.ipv4.ip_forward = 1.

Now you need to configure the DHCP server - it will distribute IP addresses to connected devices. We enter the command sudo nano /etc/dnsmasq.conf and add the following lines:

interface=wlan0
dhcp-range=198.51.100.1,198.51.100.99,255.255.255.0,24h

As you can see, the connected devices will have IP addresses in the range 198.51.100.1… 198.51.100.99.

Finally, it's time to set up Wi-Fi. Editing the file /etc/default/hostapd and enter the line there DAEMON_CONF="/etc/hostapd/hostapd.conf". Now let's edit the hostapd.conf file by entering the command sudo nano /etc/hostapd/hostapd.conf.
Enter the access point settings:

interface=wlan0
driver=nl80211
ssid=Raspberry Pi
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Here it is important to pay attention to the parameters "ssid" (access point name), "wpa_passphrase" (password), "channel" (channel number) and "hw_mode" (operation mode, a = IEEE 802.11a, 5 GHz, b = IEEE 802.11 b, 2.4 GHz, g = IEEE 802.11g, 2.4 GHz). Unfortunately, there is no automatic channel selection, so you will have to choose the least busy WiFi channel yourself.

It's important: in this test case, the password is 12345678, in a real access point, you need to use something more complicated. There are programs that brute-force passwords using a dictionary, and an access point with a simple password can be hacked. Well, sharing the Internet with outsiders under modern laws can be fraught.

Everything is ready, you can activate all services.

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl reload dnsmasq

We should now see the new WiFi hotspot in the list of networks. But in order for the Internet to appear in it, it is necessary to activate packet redirection from Ethernet to WLAN, for which we enter the command sudo nano /etc/rc.local and add the iptables configuration line:

sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE

That's it. We reboot the Raspberry Pi, and if everything was done correctly, we can see the access point and connect to it.

5 Useful Ways to Use Your Raspberry Pi

As you can see, the speed is not so bad, and it is quite possible to use such WiFi.

By the way, small council: You can change the Raspberry Pi network name by running the command sudo raspi-config. It defaults to (surprise:) raspberrypi. This is probably common knowledge. However, not everyone knows that this name is also available on the local network, but you need to add “.local” to it. For example, you can log in to your Raspberry Pi via SSH by entering the command putty [email protected]. True, there is one caveat: this works on Windows and Linux, but does not work on Android - you still have to enter the IP address manually there.

2. Media server

There are 1001 ways to make a media server on the Raspberry Pi, I will only cover the easiest one. Let's say we have a favorite collection of MP3 files and we want it to be available on the local network for all media devices. We will put a MiniDLNA server on the Raspberry Pi that can do this for us.

To install, enter the command sudo apt-get install minidlna. Then you need to configure the config by entering the command sudo nano /etc/minidlna.conf. There you need to add only one line indicating the path to our files: media_dir=/home/pi/MP3 (of course, the path may be different). After closing the file, restart the service:

sudo systemctl restart minidlna

If we did everything right, we will have a ready-made media server on the local network from which you can play music via a desktop WiFi radio or via VLC-Player in Android:

5 Useful Ways to Use Your Raspberry Pi

Council: Uploading files to Raspberry Pi is very convenient with WinSCP - this program allows you to work with RPi folders as easily as with local ones.

5 Useful Ways to Use Your Raspberry Pi

3. SDR receiver

If we have an RTL-SDR or SDRPlay receiver, we can use it on the Raspberry Pi using the GQRX or CubicSDR program. This will allow you to have an autonomous and silent SDR receiver that can work even around the clock.

I apologize for the quality of the screenshot from the TV screen:

5 Useful Ways to Use Your Raspberry Pi

With the help of RTL-SDR or SDRPlay, it is possible to receive various radio signals with a frequency of up to 1 GHz (even a little higher). For example, you can listen not only to the usual FM radio, but also the conversations of pilots or other services. By the way, radio amateurs with the help of Raspberry Pi may well receive, decode and send signals to the server WSPR and other digital modes.

A detailed discussion of SDR radio is beyond the scope of this article, you can read more here.

4. Server for "smart home"

For those who want to make their home smarter, you can use the free OpenHAB program.

5 Useful Ways to Use Your Raspberry Pi

This is not even just a program, but a whole framework that has various plugins, scripts that allow you to control various devices (Z-Wave, Philips Hue, etc.). Those who wish can study in more detail off.site https://www.openhab.org.

By the way, since we are talking about the "smart home", the Raspberry Pi may well run an MQTT server that can be used by various local devices.

5. Client for FlightRadar24

If you are an aviation enthusiast and live in an area where FlightRadar coverage is poor, you can help the community and all travelers by installing a receiver. All you need is an RTL-SDR receiver and a Raspberry Pi. As a bonus, you will get free access to the FlightRadar24 Pro account.

5 Useful Ways to Use Your Raspberry Pi

Detailed instructions already published on Habr.

Conclusion

Of course, not everything is listed here. The Raspberry Pi has a lot of processing power and can be used in a variety of tasks, from a retro game console or video surveillance, to license plate recognition, or even as a service for astronomy. all-sky cameras to watch meteors.

By the way, what was written is relevant not only for the Raspberry Pi, but also for various “clones” (Asus Tinkerboard, Nano Pi, etc.), all programs will most likely work there too.

If the audience is interested (which will be determined by the ratings for the article), the topic can be continued.

And as usual, good luck to everyone.

Source: habr.com

Add a comment