ethernet connection from RPi to laptop


11 posts
by katesfb » Wed Aug 29, 2012 4:04 am
Hi,
Have had the RPi for a couple of weeks now and all is going well. Have written a python logging application (with GUI) that takes serial input from a sensor via a USB serial cable and writes collected data to an external USB flash drive. What we are also hopping to is to setup the pi in remote areas to undertake environmental logging/monitoring applications. So it would be nice for the user to be able to just hookup to the pi with an ether-net cable to be able to view a graphical instance of what is happening on the python program and make any changes instead of having to take a spare monitor/keyboard/mouse etc. I have read posts that use VNC to communicate with the pi over a network from a laptop and have setup tightvncserver on the pi and xtightvncserver and putty on a windows laptop but really need to be able to communicate directly since a network will not be available. Is this just a case of setting a static IP address? is there a tutorial that will show me how to accomplish this?

Any help is much appreciated.

Cheers.
Posts: 20
Joined: Tue Aug 14, 2012 4:17 am
by jackokring » Wed Aug 29, 2012 4:12 am
You'll need a cat5e cross-over patch cable, so as to not need a Ethernet switch or hub. Setting a static IP on the Pi would be essential unless your windows PC is running a DHCP server service. (Although someone should check if internet connection sharing runs a simple DHCP).
Pi=B256R0USB CL4SD8GB Raspbian Stock. https://sites.google.com/site/rubikcompression/strictly-long
User avatar
Posts: 751
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
by itimpi » Wed Aug 29, 2012 7:22 am
Cross-over cable is not a requirement. The Pi ethernet port (as do those on most laptops) auto-senses if cross-over is required and acts acordingly.
Posts: 1027
Joined: Sun Sep 25, 2011 11:44 am
Location: Potters Bar, United Kingdom
by katesfb » Wed Aug 29, 2012 10:54 am
Hi,
And thanks for the replies. Since i am connecting directly from the pi to the laptop what do i put for the gateway in /etc/network/interfaces, normally it would be whatever the router is but in this case there is no router or network.

Cheers.
Posts: 20
Joined: Tue Aug 14, 2012 4:17 am
by itimpi » Wed Aug 29, 2012 11:02 am
katesfb wrote:Hi,
And thanks for the replies. Since i am connecting directly from the pi to the laptop what do i put for the gateway in /etc/network/interfaces, normally it would be whatever the router is but in this case there is no router or network.

If you just want the Pi to talk to the laptop then you do not need a gateway setting as they will be on the same subnet.
Posts: 1027
Joined: Sun Sep 25, 2011 11:44 am
Location: Potters Bar, United Kingdom
by Jonn » Thu Aug 30, 2012 3:52 am
It sounds like one could configure Internet Connection Sharing on the laptop as host, and use the default for the RPi. (This indicates the host will provide the IP: http://support.microsoft.com/kb/306126.) It sounds like one could then just connect and reboot the RPi, and the RPi should get an IP from the laptop.
Posts: 27
Joined: Wed Aug 01, 2012 12:15 pm
by katesfb » Tue Sep 18, 2012 11:32 am
HI,
And thanks for the replies. I am still having issues getting this direct Ethernet cable connection to work. This is what i have done so far:
Setup static IP address in /etc/network/interfaces in RPi;

auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.250.2
netmask 255.255.255.0

Enable SSH in RPi (Enabled via raspi-config).

Then in a windows laptop i used putty to connect to RPi by putting 192.168.250.2 into the connection box. The result is "connection error: no route to host". I have also tried other addresses such as 192.168.250.5 but the result is the the same. Do i need to alter the TCP/IP setup on the laptop although i have been told i dont have to.

I can connect to the RPi from a PC via our network using a dynamically assigned IP and putting this IP into putty and everything works fine but i need to be able to connect by direct Ethernet cable.

Any help is much appreciated.

Cheers.
Posts: 20
Joined: Tue Aug 14, 2012 4:17 am
by RaTTuS » Tue Sep 18, 2012 11:41 am
if the RPi is static
then you will have to configure the laptop to use the Ethernet as a static link also [because you will not have a dhcp server on the laptop]
the gateway on the RPi will be the laptop ip address
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
"That's not right, the badgers have moved the goalposts."
User avatar
Posts: 4159
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by brs » Tue Sep 18, 2012 12:25 pm
Internet connection sharing should not require a static IP, as the PC acts as a DHCP server for the shared local LAN. (I only tried this with a mac: http://blog.kugelfish.com/2012/09/raspberry-pi-tethering.html).

Enabling avahi-daemon (http://en.wikipedia.org/wiki/Avahi_(software)) allows to connect to the board by its hostname instead of having to figure out its IP address (e.g. raspberrypi.local). And turning on IPv6 support is probably the easiest way to do link-local networking without any configuration (assuming the PC supports IPv6 and mDSN zero-conf).
Posts: 64
Joined: Fri Aug 17, 2012 9:27 pm
Location: Zurich
by hgreen » Wed Sep 26, 2012 8:19 am
I had exactly the same requirements as you, and found I had to install the DHCP server daemon on the RPi, so that when I plugged the network cable from the laptop, the laptop's network card gets assigned a compatible network address that is visible to both sides.

The alternative to running the DHCP server, which also worked for me, was to go into the network adaptor IPv4 settings (on the laptop) and configure it to use a static IP address on the same subnet.

I didn't have to specify a gateway address.

Here's the list of steps I took for your reference...

Code: Select all
#
# Setting up the DHCP server on the RPi
# Ref: http://wiki.debian.org/DHCP_Server
#

# update the package manager (the local package list)
sudo apt-get update

# install the DHCP server
sudo apt-get install isc-dhcp-server

cd /etc/dhcp
sudo cp dhcpd.conf dhcpd.conf.backup

sudo nano dhcpd.conf

#
# 1. comment out the two option definitions a the top of the file

# 2. uncomment the 'authorative' option

# 3. add the following network definition
# This is a very basic subnet declaration.
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.2 192.168.0.20;
}


#
# Setting up a static IP address for the RPi
# Ref: http://raspberrypi.stackexchange.com/a/760/1459
#
cd /etc/network
sudo cp interfaces interfaces.backup

sudo nano interfaces

# Enter ...
auto lo eth0
iface lo inet loopback
iface eth0 inet static
    address 192.168.0.202
    netmask 255.255.255.0

# make a backup of this new file
sudo cp interfaces interfaces.static

#
# Restart the RPi with the ethernet cable plugged directly into a computer (e.g. laptop).
# Try to SSH into it via putty on the laptop - target is 192.168.0.202 (port 22).
# Confirm you can login
#
Posts: 9
Joined: Tue Sep 04, 2012 1:32 am
Location: Perth, Australia
by ely_peddler » Mon Nov 26, 2012 2:10 pm
I followed the above instructions but found they are missing a crucial part.

The eth0 interface isn't brought up until there is a cable attached, so if you boot the pi without a cable it won't have an IP and the dhcp server won't start.

So you need to get the dhcp server to start when the cable is connected, to do this you edit /etc/ifplugd/action.d/ifupdown adding in lines to bring the dhcp server up and down. You could also get it to run other server for example http.

Here's my new version of ifupdown (not I am using udhcp not isc-dhcp so the starting script name is slightly different)

Code: Select all
#!/bin/sh
set -e

case "$2" in
up)
   /sbin/ifup $1
   /etc/init.d/udhcpd start
   ;;
down)
   /etc/init.d/udhcpd stop
   /sbin/ifdown $1
   ;;
esac


Hope that helps
Posts: 6
Joined: Sun Nov 25, 2012 8:50 pm