sâmbătă, februarie 14, 2015

Life of RaspberryPI: Connect the PI to the internet.

Hi everyone,

In the previous post I showed you how to install Raspbian and how to connect to you Raspberry PI.
Now, you may want to connect it to the internet. There are many ways to do it.


1. USB tethering from mobile phone

This method saves your RJ-45 port which you can continue to use for SSH connection.

First, you have to connect your mobile phone to one Raspberry PI USB port via microUSB cable.
In your phone go to Settings > Tethering > USB Tethering. Check the button to enable the connection.

On RaspberryPI send the command:
root@raspberrypi:~# sudo dhclient usb0
root@raspberrypi:~# ping google.com
PING google.com (80.97.208.35) 56(84) bytes of data.
64 bytes from 80.97.208.35: icmp_req=1 ttl=53 time=49.6 ms
Now you can see that the internet is working if you ping Google.

2. Share your Wi-Fi through your LAN cable

Let's say your laptop is connected to a Wi-Fi hotspot (e.g. your router).
The RaspberryPI is connected with your laptop through LAN cable.

Go to Control Panel > Network and Internet > Network and Sharing Center
Click on Change Adapter Settings (left panel).
Right click on the Wireless Network Connection > Properties > Share
Check Allow other network .... and select Local Area Connection. Press Ok.

Now, click on Local Area Connection > Properties > IP v4 > Properties
and make sure it will take an IP automatically:
Start Menu > Run > cmd  and type ipconfig:


Now, copy this IP and add it to cmdline.txt located on the microSD card:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait ip=169.254.1.1::169.254.165.161

You can do this by either plugging the microSD into the laptop and edit the file with Notepad, or you can edit the file through Putty:

root@raspberrypi:/# cd /boot
root@raspberrypi:/boot# vi cmdline.txt




Similarly, edit the file /etc/resolv.conf to look like this:
root@raspberrypi:~# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
These two lines are the Google DNS servers. It helps your device locate websites and hostnames. Now, reboot your device:
root@raspberrypi:/boot# reboot
Broadcast message from root@raspberrypi (pts/1) (Sat Feb 14 11:02:52 2015):
The system is going down for reboot NOW!
After reboot:

root@raspberrypi:~# ping google.com
PING google.com (80.97.208.24) 56(84) bytes of data.
64 bytes from 80.97.208.24: icmp_req=1 ttl=53 time=598 ms
64 bytes from 80.97.208.24: icmp_req=2 ttl=53 time=34.3 ms
So it works!

0 comentarii:

Trimiteți un comentariu