Arduino Communications Using the netcat(nc) Utility

From Combustory
Revision as of 19:20, 8 November 2012 by Jvaughters (Talk | contribs)
Jump to: navigation, search

Welcome to Combustory


Any questions or comments:

  • Send them to - combustor@combustory.com

Contents

Overview

Why reinvent the wheel. I have seen very complicated methods for communicating with the Arduino, Including some I have made on my own. What I have recently found out is that the easiest way to communicate to the Arduino is using the existing tool netcat. It is soooooo simple and super powerful. You can send the output to a Network port and access the communications from literally any place in the world.

nc Versions

One thing that you have to realize is that there are more versions of netcat than there are versions of linux. Ok maybe that is a stretch, but it seems that every system that I use has a different version with different options or worse same option that acts differently. This is generally not an issue if you use the main versions of linux as they have come to use the same version. However, if you are using embedded linux with busybox, then make sure you look at the help to get the options. In general I recommend always looking at the help of nc(netcat) just to make sure, because I am constantly getting confused on which options to use on this command.

There is also some windows versions that have with or without the -e option that is considered a gaping security hole, which is really quite over blown considering the other utilites that can do the same thing. But the claim on the securlty issue is quite ridiculas considering that you can still accomplish the same task using fifo's on linux. Windows is not as easy considering that you do not have the ability to create a fifo so easily from the command line. If you plan on using Windows, make sure you get the version with the -e aka - Gaping Security Hole.

Assumptions

  • You have basic knowledge of command line usage
  • You know how to load a program to the Arduino

Linux

Mini2440 or Embedded Systems

Embedded systems like the Mini2440, use Busy Box as a small utility package that includes a version of nc that makes communications to Arduino a breeze. All you have to do is go to a terminal and use these two commands after you plug in the Arduino.

stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
nc -f /dev/ttyUSB0

You should now have a terminal session that is communicating with the Arduino. Of course you should have a program that responds to serial communication on the Arduino, or nothing will be happening. How this works is the nc command has redirected the input and output streams of the /dev/ttyUSB0, which is the Arduino terminal and the stty command sets the serial communication parameters. To exit out of the program, just use ^C (ctrl-c)


Now we expand on this idea and we send the Arduino serial port to a network port with this command.

nc -ll -p 2111 -e nc -f /dev/ttyUSB0

This is where it gets interesting. Now you can access your Arduino from anywhere on the planet, or space if you still have a good satellite connection `,~) Use this command from any other computer that has netcat.

nc 192.168.30.206 2111

Use the ip of your Mini2440 of course.

Personal tools
Sponsers
Your Ad Here
Your Ad Here