Verkostoituminen: Pieni hännän päähän pään vadelma Pi

innokas saada syvemmälle robottille sen jälkeen, kun olet kasvanut varvasteen veteen BB-8 Droidin kanssa, ostin vadelma PI 3 -malli B. Ensimmäinen askel oli muodostaa yhteyden siihen. Mutta vaikka se on sisäänrakennettu 802.11n langaton, aluksi ei ollut langaton yhteyspiste, vaikka lopulta sain yhden. Tämä ilmoitti, että menin läpi eri tapoja löytää se ja liittää siihen työpöydän tietokoneen kanssa. Ehdottomasti on muita, jotka haluavat tehdä samoin, joten katsokaamme salaisia ​​herättäjiä, joita käytetään liittämään PI tietokoneeseen suoraan ja epäsuorasti.

Miksi yhdistää Piin pöytätietokoneestani? Loppujen lopuksi on olemassa pieniä näytöitä ja näppäimistöjä, joita hakkerit käyttävät usein PI-kannettavien tietokoneiden ja PI-tablettien tekemiseen. Koska aion upottaa PI eri robotteihin, en nähnyt erillistä näyttöä ja näppäimistöä, mutta katsoin hieman tekemästä niin.

Työpöydän näytön käyttäminen käyttää VGA-liitintä, mutta VGA-HDMI-sovitin, jonka olen mennyt PI: n kanssa. Myös työpöydän antiikin Keytronic-näppäimistö käyttää PS / 2-liitintä niin, että se ei ollut käyttökelpoinen. Vaikka PS / 2-to-USB-sovittimet ovat olemassa, tutkimukseni osoitti, että tarvitsen sitä, jolla on USB-älykkäät, kuten näppäimistö pystyy USB: llä eikä sillä ole tällaista elektroniikkaa. (Mutta sillä on makea, syvä tactile avaimet!) PI olisi pysynyt pääylittömästi, ja minä ohjelmoin sen yhdistämällä siihen työpöydän tietokoneesta.

Liittäminen suoraan Ethernet-kaapelin avulla

Kotimodemi oli myös muinainen, ei ollut langatonta. Sillä oli myös vain yksi Ethernet-portti. Tämä ilmoitti yhdistää työpöydän tietokoneen joko modeemiin tai vadelmaan Piin, mutta ei molemmat samanaikaisesti. Joten irrottamalla PI, ainoa tapa yhdistää se tietokoneeseeni oli irrottaa Ethernet-johto modeemista ja liittää sen Piin. Tämä ilmoitti ilman Internet-yhteyttä työskennellessäsi PI, tuskin ihanteellinen, mutta tarpeeksi hyvä, jos PI työskenteli lainkaan.

Mutta tietokoneeni puhua PI: lle, tarvitsin PI: n IP-osoitteen. Niille, jotka eivät tunne IP-osoitteita, ne koostuvat neljästä numerosta, jotka vaihtelevat 0 – 255, jotka on erotettu pisteiksi. Esimerkiksi:

169.254.95.208

Se on todella 32-bittinen luku, mutta se on kirjoitettu tällä tavalla luettavuudelle.

Verkko- ja jakamiskeskus Windowsissa
IP-osoite ja aliverkon peite

Menossa Windowsin ohjauspaneeliin työpöydälläni ja sitten verkko- ja jakamiskeskuksessa, voisin nähdä, että verkko on nyt olemassa.

Klikkaamalla näkymän tilaa ja mene syvemmälle löysin hyödyllisiä tietoja. Ensimmäinen oli työpöydän tietokoneen IP-osoite, 169.254.95.208. IPv4 kertoo minulle, että se käyttää Internet-protokollaa versiota 4. IPv6: n IP-osoitteet eroavat ainakin, koska ne ovat neljä kertaa niin kauan.

Lisäksi IPv4-aliverkon maskin läsnäolo 255.255.0.0 kertoi minulle, että aliverkko tai aliverkko oli muodostettu kahden koneen välillä. Aliverkko on joukko koneita, jotka muodostavat pienemmän verkon, joka voi olla osa suurempaa. Their IP addresses all start with the same binary values, though just how lots of bits at the beginning they have in common varies. Mistä tiedät, mitkä bit ovat yleisiä?

Käyttämällä aliverkon peite
Siellä aliverkon peite tulee sisään. Jos haluat selvittää, mitkä bittiä, ota aliverkon peite ja tee bittinen ja sen valmistajan IP-osoite kyseisessä aliverkossa. Kuten kaavio osoittaa, tapaukseni tulos oli 169.254.0.0, mikä osoittaa, että PI: n IP-osoite on aloitettava 169,254: llä. Toinen tapa kirjoittaa aliverkon peite on CIDR-merkinnässä. CIDR-merkinnässä IP-osoitetta seuraa A / ja sitten jaettujen bittien määrä. Tällöin se olisi 169.254.0.0/16. Viimeiset kaksi numeroa ovat nollia, mutta heidän ei tarvitse harkita, että 16 kertoo, mitä pitää. Tämä CIDR-merkintä tulee olemaan hyödyllinen.

Vaikka 169,254 oli jaettu, se jäi edelleen 65 536 (256 × 256) mahdollisia yhdistelmiä kahdelle jäljellä olevalle numerolle. Voit skannata verkkoa läpi jokaisen mahdollisen numeron yhdistelmää, jota käytin NMAP.org.

‘Nmap -sn’ skannaustulokset
Kuten Snapshot näytetään, juoksin sen Cygwin-ikkunassa, vaikka myös GUI-versioita saatavilla myös. Käytin seuraavaa komentoriviä.

NMAP -SN 169.254.0.0/16

Huomaa, että aliverkon peite annetaan CIDR-merkinnän avulla. Snapshot-osio ilmestyi noin 10 minuutin kuluttua, mikä osoitti, että se kestää kauan skannauksen 169.254.0.0 – 169.254.37.77, PI: n IP-osoite. 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 for SSH terminal
VNC desktop

Now that I had it connected, I needed a terminal running a safe shell (SSH) into the Pi on the desktop computer. Setting up the terminal was simply a matter of downloading the popular PuTTY program and running it. In the Session section, I filled in the Pi’s IP address, port 22, and made sure SSH was selected. That opened up a terminal window with a login prompt. The default username is pi and the password is raspberry. Of course the first thing I did was run the passwd utility to change the password.

Alternatively you can get a graphical terminal instead using VNC. This is a graphical desktop that runs in a window on you desktop computer but is really a terminal into the Pi.

Connecting by means of Ethernet using A Wireless Router

It wasn’t long after getting my Pi that I made a decision to switch to a wireless router / fiber modem combo. As a bonus, this upgrade also includes multiple Ethernet ports. I set up my desktop computer to use wireless, but I couldn’t do the same for the Pi just yet. I had to do some configuration on the Pi to set up the wireless, and so I had to connect using Ethernet first.

Router network information in a browser
Connecting to the router with Ethernet was far much easier than the direct-connection method covered above considering that no scanning was involved. Once I’d connected the Pi using an Ethernet cable, I simply brought up a browser on my desktop computer and typed the router’s IP address into the browser’s URL bar at the top. This is an address like 192.168.1.1 or 192.168.2.1, but with http:// in front of it, though some browsers don’t need the http://. check your router/modem manual.

What you see depends on your modem, but mine displayed a network graph at the bottom with the Pi’s IP address, 192.168.2.14. with that I was able to bring up a terminal using PuTTY as described above.

If you want to remain using Ethernet between your Pi and the modem then you’re done. but I wanted to go wireless so that my robots could wander around without a trailing Ethernet cable. now that I had a terminal into the Pi I could go on to the next step.

Connecting Wirelessly

The Raspberry Pi 3 model B has wireless built-in, but if you have a version without wireless then you can also get a wireless dongle that plugs into one of the Pi’s USB ports. Before you can connect to the headless Pi wirelessly, you’ll still need to connect to it using one of the above methods first, and do some configuration on the Pi.

I brought up a terminal and logged in as described above. I needed to put my wireless network name and network password into the configuration file /etc/wpa_supplicant/wpa_supplicant.conf.  But for safety reasons, I didn’t want the password to be in plain text.

Using wpa_passphrase and editing wpa_supplicant.conf
Editing wpa_supplicant.conf
So I ran wpa_passphrase “bobsnetname” “bobsnetpassword” and highlighted the output, which in this terminal, copies the highlighted text to the clipboard. “bobsnetname” and “bobsnetpassword” are of course fictitious.

I then edited /etc/wpa_supplicant/wpa_supplicant.conf and pasted from the clipboard by right-clicking. The pasted text still included a line with the password in clear text. It was commented out but nonetheless, visible, so I deleted it.

After saving, and exiting the editor I disconnected the Ethernet cable. A running program called wpa-supplicant should have taken only a few seconds after the file was changed to notice it and get the wireless going. And so after waiting a few seconds I ran ping google.com. Se toimi. The Pi was connected wirelessly.

Had it not been then I could have restarted it manually by running sudo wpa_cli reconfigure. This also reports the interface name, wlan0 in my case.

Running ‘ifconfig wlan0’
To additionally test it, and to get the Pi’s IP address, I ran ifconfig wlan0 and looked for the IP address beside the inet addr. It was there and with it I could connect to the Pi and start programming robots.

Those were my experiences in connecting to my Raspberry Pi, but we know that there are lots of Raspberry Pi users on 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.

Leave a Reply

Your email address will not be published. Required fields are marked *