NETWORKING: PIN THE TAIL ON THE HEADLESS RASPBERRY PI

June 5, 2022 0 By gaaxo

eager to get deeper into robotics after dipping my toe in the water with my BB-8 droid, I purchased a Raspberry Pi 3 model B. The first step was to connect to it. but while it has built-in 802.11n wireless, I at first didn’t have a wireless access point, though I eventually did get one. That indicated I went through different ways of finding it and connecting to it with my desktop computer. definitely there are others seeking to do the same so let’s take a look at the secret incantations used to connect a Pi to a computer directly, and indirectly.

Why connect to the Pi from my desktop computer? After all, there are small monitors and keyboards that hackers frequently use to make Pi laptops and Pi tablets. Since I was going to be embedding the Pi in various robots,  I saw no need to purchase a separate monitor and keyboard for it, but I did look a little into doing so.

My desktop’s monitor uses a VGA connector but the VGA-to-HDMI adapter I gotten along with the Pi didn’t work. Also, my desktop’s ancient KeyTronic keyboard uses a PS/2 connector so that wasn’t usable either. though PS/2-to-USB adaptors do exist, my research showed that I’d need the one that has USB smarts in it, as my keyboard predates USB and has no such electronics of its own. (But it does have sweet, deep tactile keys!) My Pi would remain headless, and I’d program it by connecting to it from my desktop computer.

Connecting directly by means of Ethernet Cable

My home modem was also ancient, having no wireless. It also had only one Ethernet port. That indicated I could connect my desktop computer either to the modem or to the Raspberry Pi but not both at the same time. So on unboxing the Pi, the only way to connect it to my computer was to unplug the Ethernet cord from the modem and plug it into the Pi instead. That indicated no Internet access while working with the Pi, hardly ideal, but good enough to see if the Pi worked at all.

But for my computer to speak to the Pi, I needed the Pi’s IP address. For those not familiar with IP addresses, they consist of 4 numbers ranging from 0 to 255 separated by dots. Například:

169.254.95.208

It’s really a 32-bit number but it’s written that way for readability.

Network and Sharing center in Windows

IP address and subnet mask

Going to the Windows control panel on my desktop and then the Network and Sharing Center, I could see that a network now existed.

Clicking on view status and going deeper I found some beneficial information. The first was the IP address of the desktop computer, 169.254.95.208. The IPv4 tells me that it’s using Internet Protocol version 4. The IP addresses in IPv6 differ at least in that they’re four times as long.

Further, the presence of the IPv4 Subnet Mask, 255.255.0.0 told me that a subnet, or subnetwork, had been formed between the two machines. A subnet is a group of machines making up a smaller network that may or may not be a part of a larger one. Their IP addresses all start with the same binary values, though just how lots of bits at the beginning they have in common varies. how do you know which bits are common?

Using the subnet mask
That’s where the subnet mask comes in. To find out which bits, take the subnet mask and do a bitwise and with the IP address of a maker on that subnet. As the diagram shows, the result in my case was 169.254.0.0, indicating that the Pi’s IP address must start with 169.254. another way of writing the subnet mask is in CIDR notation. In CIDR notation the IP address is followed by a / and then the number of shared bits. In this case it would be 169.254.0.0/16. The last two numbers are zeros but they need not be considering that the 16 tells you what to keep. This CIDR notation will come in helpful shortly.

Though the 169.254 was shared, that still left 65,536 (256×256) possible combinations for the two remaining numbers. To scan the network, going through every possible combination of numbers, I used nmap, downloadable from nmap.org.

‘nmap -sn’ scan results
As shown in the snapshot, I ran it in a cygwin window though there are GUI versions available too. I used the following command line.

nmap -sn 169.254.0.0/16

Note that the subnet mask is given using CIDR notation. The section about the Raspberry Pi that you see in the snapshot appeared after around 10 minutes, indicating that it took that long to scan from 169.254.0.0 to 169.254.37.77, the Pi’s IP address. even though that was what I was looking for, I left it going anyway and the full scan took just over forty-four minutes. during that time it also found my desktop computer, the host from which it was doing the scan. had the Pi’s IP address been 169.254.255.255 then it would have taken the full forty-four minutes before finding it.

The Pi’s IP address continued to be 169.254.37.77 across shutdowns and so scanning again was not necessary.

Starting Up A terminal and VNC DesktopPutty pro terminál SSH

VNC Desktop.

Teď, když jsem ho připojil, potřeboval jsem terminál běh bezpečný shell (SSH) do PI na stolním počítači. Nastavení terminálu byl jednoduše záležitostí stahování populárního programu Putty a spustit jej. V sekci relace jsem vyplnil IP adresu PI, port 22, a ujistil se, že SSH byl vybrán. Které otevřelo svorkovnici s přihlašovacím řádkem. Výchozí uživatelské jméno je PI a heslo je malina. Samozřejmě, že první věc, kterou jsem udělal, byl spustit nástroj Passwd změnit heslo.

Alternativně můžete umístit grafický terminál místo používání VNC. Jedná se o grafickou plochu, která běží v okně na ploše počítače, ale je to opravdu terminál do PI.

Připojení pomocí Ethernet pomocí bezdrátového routeru

Nebylo dlouho poté, co jsem dostal své PI, rozhodl jsem se přepnout na bezdrátový směrovač / vláknový modem Combo. Jako bonus obsahuje tento upgrade také více ethernetových portů. Nastavil jsem stolní počítač, který používám bezdrátový, ale nemohl jsem udělat totéž pro PI ještě. Musel jsem udělat nějakou konfiguraci na PI pro nastavení bezdrátového připojení, a proto jsem musel nejprve připojit pomocí Ethernetu.

Informace o síti směrovače v prohlížeči
Připojení k směrovači s Ethernetem bylo mnohem snazší než metoda přímého spojení, na které se vztahuje výše, s ohledem na to, že nebyl zapojen žádné skenování. Jakmile jsem připojil PI pomocí kabelu Ethernet, jednoduše jsem vyvedl prohlížeč na počítači na stolní počítače a zadal IP adresu routeru do panelu URL prohlížeče nahoře. Jedná se o adresu jako 192.168.1.1 nebo 192.168.2.1, ale s http: // před ní, i když některé prohlížeče nepotřebují http: //. Zkontrolujte příručku směrovače / modemu.

To, co vidíte, závisí na vašem modemu, ale moje zobrazuje síťový graf v dolní části adresy IP PI, 192.168.2.14. S tím jsem byl schopen vyvolat terminál pomocí tmelu, jak je popsáno výše.

Pokud chcete zůstat pomocí Ethernet mezi PI a modemem, pak jste hotovi. Ale chtěl jsem jít bezdrátové, aby se moji roboty mohli putovat bez koncového ethernetového kabelu. Teď, když jsem měl terminál do PI, mohl bych jít na další krok.

Připojení bezdrátově

Model Raspberry PI 3 B má bezdrátový vestavěný, ale pokud máte verzi bez bezdrátového připojení, můžete také získat bezdrátový dongle, které zapojují do jednoho z portrétů USB PI. Než se můžete připojit k bezhlavě bezdrátově, stále se musíte připojit k ní pomocí jedné z výše uvedených metod, a udělat nějakou konfiguraci na PI.

Zvedl jsem terminál a přihlásil se, jak je popsáno výše. Potřeboval jsem vložit své bezdrátové síťové jméno a síťové heslo do konfiguračního souboru /etc/wpa_supplicant/wpa_supplicant.conf. Ale z bezpečnostních důvodů, nechtěla jsem, aby heslo bylo v prostém textu.

Použití wpa_passprase a editace wpa_supplicant.conf
Úprava WPA_SUPPLICANT.CONF.
Tak jsem běžel WPA_PASSPHRASE “BOSSLETNAME” “BOSSNETE” a zvýraznil výstup, který v tomto terminálu zkopíruje zvýrazněný text do schránky. “BobSnetname” a “bobsewassword” jsou samozřejmě fiktivní.

Pak editoval /etc/wpa_supplicant/wpa_supplicant.conf a vložen ze schránky klepnutím pravým tlačítkem myši. Vložený text stále zahrnoval linku s heslem v jasném textu. Bylo to vyjádřeno, ale nicméně viditelné, tak jsem ji smazal.

Po ukládání a ukončení editoru jsem odpojil ethernetový kabel. Běžný program nazvaný WPA-Supplicant by měl přijmout jen několik sekund po změně souboru, aby si to upozornil a získali bezdrátové připojení. A tak po čekání několik vteřin jsem běžel ping Google.com. Fungovalo to. PI byla bezdrátově připojena.

Nebylo to pak, nemohl jsem ho restartovat ručně spuštěním sudo wpa_cli rekonfigure. To také hlásí název rozhraní, WLAN0 v mém případě.

Běh ‘ifconfig wlan0’
Kromě toho testujte a získejte IP adresu PI, běžel jsem ifconfig WLAN0 a hledal IP adresu vedle ANDR. Bylo to tam a s ním jsem se mohl připojit k PI a začněte programovací roboty.

To byly mé zkušenosti v souvislosti s mými malinovými pi, ale víme, že existuje spousta uživatelů malinových pi na hackaday. What methods have you used, what traps have you found and what ideas do you have for getting out of them? let us know in the comments so that others don’t fall into them too.