NETWORKING: PIN THE TAIL ON THE HEADLESS RASPBERRY PI

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. علي سبيل المثال:

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 Desktopالمعجون لمحطة SSH
VNC سطح المكتب

الآن بعد أن كنت مرتبطا، كنت بحاجة إلى محطة تشغيل قذيفة آمنة (SSH) في PI على كمبيوتر سطح المكتب. كان إعداد المحطة ببساطة مسألة تنزيل برنامج المعجون الشهير ويديره. في قسم الجلسة، قمت بملء عنوان IP الخاص ب PI، المنفذ 22، وتأكد من اختيار SSH. التي فتحت نافذة محطة مع موجه تسجيل الدخول. اسم المستخدم الافتراضي هو PI وكلمة المرور هو التوت. بالطبع أول شيء قمت بتشغيل الأداة المساعدة Passwd لتغيير كلمة المرور.

بدلا من ذلك، يمكنك الحصول على محطة بيانية بدلا من ذلك باستخدام VNC. هذا سطح مكتب رسومي يعمل في نافذة على جهاز كمبيوتر سطح المكتب، لكنه حقا محطة في PI.

الاتصال عن طريق إيثرنت باستخدام جهاز توجيه لاسلكي

لم يكن لفترة طويلة بعد الحصول على بي الذي اتخذته قرارا بالتبديل إلى كومبو جهاز توجيه / مودم ألياف لاسلكي. ككافأة، تتضمن هذه الترقية أيضا منافذ إيثرنت متعددة. أقضيت جهاز الكمبيوتر المكتبي الخاص بي لاستخدام اللاسلكي، لكنني لم أستطع فعل الشيء نفسه بالنسبة ل PI بعد. اضطررت للقيام ببعض التكوين على PI لإعداد اللاسلكية، لذلك كان علي الاتصال باستخدام Ethernet أولا.

معلومات شبكة التوجيه في متصفح
كان الاتصال بجهاز التوجيه باستخدام Ethernet أسهل بكثير من طريقة الاتصال المباشر المغطاة أعلاه بالنظر إلى أنه لم يشارك أي مسح. بمجرد توصيل PI باستخدام كابل Ethernet، قامت ببساطة بإنشاء مستعرض على كمبيوتر سطح المكتب الخاص بي وكتبت عنوان IP الخاص ب Router في شريط URL الخاص بالمتصفح في الأعلى. هذا عنوان مثل 192.168.1.1 أو 192.168.2.1، ولكن مع http: // أمامه، على الرغم من أن بعض المتصفحات لا تحتاج إلى http: //. تحقق دليل جهاز التوجيه / المودم الخاص بك.

يعتمد ما تراه على المودم الخاص بك، لكن الألغام عرض رسم بياني للشبكة في الأسفل مع عنوان IP الخاص ب PI، 192.168.2.14. مع ذلك كنت قادرا على طرح محطة باستخدام المعجون كما هو موضح أعلاه.

إذا كنت ترغب في البقاء استخدام Ethernet بين PI الخاص بك والمودم، فأنت انتهيت. لكنني أردت أن أذهب لاسلكيا حتى يتجول روبوتاتي دون كابل إيثرنت زائدة. الآن بعد أن كان لدي محطة في PI يمكن أن أذهب إلى الخطوة التالية.

الاتصال لاسلكيا

يحتوي Top Raspberry Pi 3 Model B على مدمج لاسلكي، ولكن إذا كان لديك إصدار بدون اتصال لاسلكي، فيمكنك أيضا الحصول على دونجل لاسلكي يقوم بتوصيل واحدة من منافذ USB الخاصة ب PI. قبل أن تتمكن من الاتصال ب Pi مقطوعة الرأس لاسلكيا، ستظل بحاجة إلى الاتصال به باستخدام إحدى الطرق المذكورة أعلاه أولا، وقم ببعض التكوين على PI.

لقد طرحت محطة وتسجيل الدخول كما هو موضح أعلاه. كنت بحاجة إلى وضع اسم الشبكة اللاسلكية الخاصة بي وكلمة مرور الشبكة في ملف التكوين /etc/wpa_supplicant/wpa_supplicant.conf. ولكن لأسباب تتعلق بالسلامة، لم أرغب في أن تكون كلمة المرور في نص عادي.

باستخدام WPA_PassPhrase وتحرير WPA_Supplicant.conf
تحرير wpa_supplicant.conf.
لذلك أجرت WPA_PASPSPhrase “BobsnetName” “BobsnetPassword” وأبرز الإخراج، والتي في هذه المحطة، نسخ النص المميز على الحافظة. “bobsnetname” و “bobsnetpassword” هي بالطبع وهمية.

ثم قمت بتحرير /etc/wpa_supplicant/wpa_supplicant.conf ولصق من الحافظة بالنقر بزر الماوس الأيمن. لا يزال النص المعصق متضمن خطا بكلمة مرور نص واضح. وقد علق ولكن مع ذلك، مرئية، لذلك حذفت ذلك.

بعد الحفظ، وإخراج المحرر أنا قطع اتصال كبل Ethernet. يجب أن يستغرق برنامج قيد التشغيل يسمى WPA-FOULCANT فقط بضع ثوان بعد تغيير الملف لإشعاره والحصول على الذهاب اللاسلكي. وهكذا بعد الانتظار بضع ثوان، ركضت بينغ Google.com. انها عملت. تم ربط PI لاسلكيا.

لم يكن بعد ذلك كان بإمكاني إعادة تشغيله يدويا عن طريق تشغيل إعادة تكوين Sudo WPA_CLI. هذا يبلغ أيضا عن اسم الواجهة، WLAN0 في حالتي.

تشغيل “IFConfig WLAN0”
لإختبارها بالإضافة إلى ذلك، والحصول على عنوان IP الخاص ب PI، قمت بإدارة IFConfig WLAN0 ونظرت عن عنوان IP بجانب Inet Addr. كان هناك ومع ذلك يمكنني الاتصال ب PI وبدء الروبوتات البرمجة.

تلك كانت تجاربي في الاتصال ب PI توت العليق، لكننا نعلم أن هناك الكثير من مستخدمي التوت بي في هااداي. ما هي الأساليب التي استخدمتها، ما الفخاخ الموجودة التي وجدتها وما الأفكار التي لديك للخروج منها؟ اسمحوا لنا أن نعرف في التعليقات حتى لا يسقطهم الآخرون أيضا.