Hardware Reference
In-Depth Information
Continued from previous page.
client.write(serialChar);
}
}
else {
// in case you were connected, stop the client:
client.stop();
// if you're not connected, and you get a serial C,
// attempt to connect:
if (Serial.available()) {
char serialChar = Serial.read();
if (serialChar == 'C') {
connectToServer();
}
}
}
}
void connectToServer() {
// attempt to connect, and wait a millisecond:
Serial.println("connecting...");
if (client.connect(server, 80)) {
// if you get a connection, report back via serial:
Serial.println("connected");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
client.stop();
}
}
Here's a simple Pro-
cessing sketch that
will communicate serially with the
preceding Arduino sketch to make an
HTTP request. When you type a key the
first time, it will send C to initiate a con-
nection. The second keystroke will send
the HTTP request.
Talk To It
/*
Serial-to-ethernet HTTP request tester
Context: Processing
*/
// include the serial library
import processing.serial.*;
Serial myPort; // Serial object
int step = 0; // which step in the process you're on
char linefeed = 10; // ASCII linefeed character
ยป
 
Search WWH ::




Custom Search