SerialIP Library for Arduino
Author:  Adam Nielsen
Contact: malvineous@shikadi.net


Navigation


Current version

1.0 2010-02-28: Proof of concept


Description

SerialIP is a port of the uIP TCP/IP stack to the Arduino. It allows a stock Arduino (with no shields) to access the Internet and to run Internet accessible servers.

It works by using SLIP to route TCP/IP data over the serial port, just like a dialup Internet connection (only in this case it's the Arduino "dialling up" to your PC, and there are no modems or telephone calls involved.)

Because all traffic is routed over the serial port, it means you can get network access without needing the Ethernet shield. However unlike the Ethernet shield which handles the TCP/IP protocol for you, SerialIP implements the entire TCP/IP stack (courtesy of the fine uIP project.) This has a couple of downsides, the main one being size. It takes up around 9kB of flash space and enough RAM that you can easily run out of memory (which normally results in the Arduino rebooting unexpectedly.)

However it is possible to work within these limitations, and with no additional purchase beyond the Arduino itself it's certainly a cheap introduction to the world of embedded networking!


Download and install

Download SerialIP-1.0.zip

Unzip the file into the arduino-0017/hardware/libraries/ folder. You should end up with a SerialIP folder created inside the libraries folder.

Restart the Arduino IDE and open one of the examples from the File -> Examples -> SerialIP menu. See below for a brief description of the example code.

For Arduino 1.0+: Change line 24 in 'SerialIP.h' from '#include <WProgram.h>' to '#include <Arduino.h>'


Establishing a connection

Perhaps the most difficult part of using this library is figuring out how to establish the SLIP connection to the Arduino.

The SLIP connection needs two IP addresses assigned to it. One for the PC's end and one for the Arduino's end. These two addresses must not be in use elsewhere on your network or it will cause problems with packets being sent to the wrong place and getting lost.

The defaults of 192.168.5.x will work for most people, except for those who already have devices starting with 192.168.5. on their network. If you change the addresses, remember to edit the code appropriately and reflash as the Arduino's IP is hard coded.

Linux

Under Linux, this is fairly easy if you have SLIP support compiled into your kernel: (you will need two terminal windows for this)

  • Load the kernel module

    $ sudo modprobe slip

  • Create a SLIP device (defaults to sl0) on the Arduino's serial port

    $ sudo slattach -L -s 115200 -p slip /dev/ttyUSB0

    (this command won't return, press Ctrl+C to exit. You won't be able to upload new sketches while it is running)

  • In another terminal window, configure the IP addresses on the new SLIP interface to match what the Arduino is expecting (sorry no DHCP!)

    $ sudo ifconfig sl0 192.168.5.1 dstaddr 192.168.5.2

    The first IP is the one assigned to your PC and the second one is the Arduino's.

Windows

Under Windows, you'll have to figure it out yourself and update this page :-) You should be able to use a Direct Cable Connection on XP and older, however this has apparently been removed in Vista and Win7 Home Premium. You will have to upgrade to Win7 Professional and then run in XP mode in order to use SLIP.

Setting up SLIP in XP: http://www.sics.se/~bg/telos/slipintro.pdf


Reference

Until the library interface has settled down, please see the examples for the few commands that are specific to SerialIP.

For the rest of the commands, see the uIP-1.0 documentation.


Examples

There are currently two examples:

  • HelloWorldServer listens for TCP connections on port 1000 and greets any incoming connections.

  • SendEMail connects to an SMTP server and sends an e-mail


FAQ

How do I know if I've established a connection to the Arduino?

Ping it. The uIP stack will respond to pings. If you look at your routing table the Arduino's IP address should be sent out of the SLIP connection (as opposed to being sent out your Internet connection instead.)

You can also watch the serial RX/TX LEDs on the Arduino while you're pinging it. The RX LED should flash once a second or so when the PC is sending a ping packet, and the TX LED should flash a moment later when the Arduino responds.

  • If the RX LED doesn't flash your PC hasn't established a SLIP connection or the packet is not being routed over it. Check your IP and routing configuration.

  • If RX flashes but not TX, the Arduino is ignoring the packet. Ensure the IP address you assigned to the SLIP interface matches the one in the code uploaded to the Arduino. Ensure the code is running properly, for example by using digitalWrite() to turn a LED on and off in the main loop(). Insufficient memory can cause the Arduino to reset before reaching the main loop.

  • If RX and TX do flash but you do not receive responses to pings it means the Arduino is responding but your PC is ignoring that response. Check firewalls etc.

The rest of these FAQs assume you can successfully ping the Arduino.

The Arduino can't connect to a server on my PC

Make sure you're not running a firewall that is blocking connections to your PC. Under Linux, you can give the SLIP connection full access like this:

# iptables -I INPUT 1 -i sl0 -j ACCEPT

The Arduino can't connect out to the Internet

The Arduino is only capable of talking to whatever is on the other end of the serial cable - which will usually be your desktop PC. Your PC will have to be configured to take the Arduino's packets and route them out to the Internet if you wish to connect to remote hosts.

Under Windows this is probably done by sharing the Internet connection over the SLIP interface, under Linux you can do the same probably by setting up iptables rules to masquerade (use NAT) data coming out of the SLIP interface.

More detailed instructions will be added when someone eventually tries to achieve this :-)


Last Modified: July 08, 2012, at 07:58 PM by doggenj

Share