CIRCUITS
makes it easy. Like other Lantronix devices, the
Xport has a TCP/IP stack and simple web and telnet
interfaces built in on the Ethernet side. On the serial
side, it uses the same TTL serial protocol as most
microcontrollers, including the Arduino, so hooking
them up means simply connecting the micro’s
transmit line to the converter’s receive line and
vice versa (Figure E). I used an Xport for this project
because I had a custom-printed circuit board
designed for it, but if you’re new to these devices,
you might want to start with the Lantronix Micro.
The Micro has a simpler connector and can be wired
to a solderless breadboard with an IDE connector
and a ribbon cable.
Before you can connect the Lantronix device to
the net, you have to configure it. Lantronix has a
downloadable configuration utility for Windows,
DeviceInstaller. For non-Windows users I have a
couple of programs that will do the job (one
for Java, one for Processing) available online at
makezine.com/11/diycircuits_meter.
On a network with DHCP enabled, the Lantronix
devices will obtain an address automatically. Once
you know the device’s address, you can telnet into
it to configure its serial port and network settings.
Here are the settings I used for this project:
Basic parameters
IP addr 192. 168.0.23, gateway 192. 168.0.1, netmask
255.255.255.000 ( 8 bits)
*** Channel 1
Baudrate 9600, I/F Mode 4C, Flow 00
Port 10001
Remote IP Adr: --- none ---, Port 00000
Connect Mode : D4
Disconn Mode : 00
Flush Mode : 00
Communications and Code
The microcontroller then connects to a web server
by sending the Lantronix device a connect string
that specifies the numerical address of the server
and the port number:
C204.15.193.131/80
Once a connection is made, the Lantronix device
returns a “C” to confirm. After that, any data sent
in either direction passes right through between
136 Make: Volume 11
microcontroller and server, as through a serial port
connection.
The full Arduino code for my microcontroller is
online at makezine.com/11/diycircuits_meter. It
connects to the net with a method like this:
void xportConnect() {
// send out the server address and
// wait for a "C" byte to come back.
// fill in your server's numerical address below:
Serial.print("C204.193.131/80");
status = connecting;
}
Then it waits for the Lantronix device to return with
a “C”:
if (status == connecting) {
// read the serial port:
if (Serial.available()) {
inByte = Serial.read();
if (inByte == 67) { // 'C' in ascii
status = connected;
}
}
}
Once it’s connected, it sends an HTTP request
like this:
void httpRequest() {
// Make HTTP GET request. Fill in the path to your
version
// of the CGI script:
Serial.print("GET /~myaccount/ scraper.php HTTP/1.1\
n");
// Fill in your server's name:
Serial.print("HOST: www.myserver.com\n\n");
status = requesting;
}
And the server replies:
HTTP/1.1 200 OK
Date: Fri, 14 Apr 2006 21:31: 37 GMT
Server: Apache/2.0.52 (Red Hat)
Content-Length: 10
Connection: close
Content-Type: text/html; charset=UTF- 8
< AQI: 65>