5 Ways to Use the Raspberry Pi Beneficially

Hi Habr.



Almost everyone has a Raspberry Pi at home, and I venture to suggest that many have it lying around idle. But Raspberry is not only a valuable fur , but also a very powerful fanless-computer with Linux. Today we look at the useful features of the Raspberry Pi, for the use of which the code does not have to be written at all.



For those who are interested, the details are under the cut. The article is designed for beginners.



Note : this article is intended for beginners, but having at least basic concepts of what an IP address is, how to access Raspberry Pi via SSH 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 the below, just the command line will be enough. 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 tip : the correct power supply (better branded at 2.5A, rather than noname-charging from the phone) and the heatsink on the processor are extremely important for the stable operation of the Raspberry Pi. Without this, Raspberry may freeze, file copying errors, etc. may appear. The insidiousness of such errors is that they occur only occasionally, for example, during peak CPU load or when large files are being written to an 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 are ready to install and configure.



1. WiFi access point



The Raspberry Pi is easy to turn into a wireless access point, and you don’t have to buy anything else, there is already WiFi “on board”. To do this, 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
      
      





We 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 . 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 (it is important to remember if some server will work on it, the address of which will need to be entered in the browser).



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



Now you need to configure a DHCP server - it will distribute IP addresses to connected devices. 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. We edit the file / etc / default / hostapd and enter the line DAEMON_CONF = "/ etc / hostapd / hostapd.conf" there . Now edit the hostapd.conf file by entering the command sudo nano /etc/hostapd/hostapd.conf .

Enter the parameters of the access point:



 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
      
      





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.



Important : in this test example, the password is 12345678, in a real access point you need to use something more complicated. There are programs that enumerate passwords in a dictionary, and an access point with a simple password can be cracked. 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
      
      





Now we should already see the new WiFi access point in the list of networks. But for the Internet to appear on it, you need to activate the packet forwarding from Ethernet to WLAN, for which we enter the sudo nano /etc/rc.local command 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.







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



By the way, a little tip : you can change the network name of the Raspberry Pi by running the sudo raspi-config command. By default, it is (surprise :) raspberrypi. This is probably well known. 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 Raspberry Pi via SSH by entering putty pi@raspberrypi.local . There is a truth, there is one caveat: this works on Windows and Linux, but does not work on Android - there you still have to enter the IP address manually.



2. Media server



There is a 1001 way to make a media server on the Raspberry Pi, I will consider only the simplest. Suppose 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, which 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 (the path, of course, may be different). After closing the file, restart the service:



sudo systemctl restart minidlna



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







Tip : uploading files to the Raspberry Pi is very convenient using WinSCP - this program makes working with RPi folders as easy as local ones.







3. SDR receiver



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



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







Using RTL-SDR or SDRPlay, it is possible to receive various radio signals with a frequency of up to 1 GHz (even slightly higher). For example, you can listen not only to ordinary FM radio, but also to negotiations between pilots or other services. By the way, radio enthusiasts using Raspberry Pi can very well receive, decode and send WSPR signals and other digital modes to the server.



A detailed discussion of SDR radio is beyond the scope of this article; more details can be found here .



4. Server for “smart home”



Those who want to make their home more “smart” can use the free OpenHAB program.







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



By the way, since we are talking about a “smart home”, a MQTT server that can be used by various local devices may well work on the Raspberry Pi.



5. Client for FlightRadar24



If you are an aviation enthusiast and live in a region where FlightRadar coverage is poor, you can help the community and all travelers by installing the 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.



image



The detailed instruction was already published on Habré.



Conclusion



Of course, not all are listed here. Raspberry Pi has good computing power, and can be used in completely different tasks, from a retro-game console or video surveillance, to recognition of car numbers or even as a service for an astronomical all-sky camera for observing meteors.



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



All successful experiments.



Continuation is available in the second part .



All Articles