I'm having an issue with the Arduino Ethernet library and I'm hoping I can get some pointers.
Essentially it boils down to this: I want to detect an incoming connection WITHOUT having to have the server send something followed by a carriage return.
Kind of hard to follow just what you want to do. Below is some telnet servo test code that echos back to the telnet client and to the serial monitor. A comma , is used as the packet delimiter. Using the telnet client send a servo us position like 1500, and see the result.
//zoomkat 2-05-13
//simple arduino telnet server test
//for use with IDE 1.0
//servo us typed in telnet client is echoed back from arduino server
//a comma , is used as a delimiter, use serial monitor to monitor
//for use with W5100 based ethernet shields
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
String readString;
Servo myservoa, myservob, myservoc, myservod; // create servo object to control a servo
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
// telnet defaults to port 23
EthernetServer server = EthernetServer(23);
void setup()
{
Serial.begin(9600);
Serial.println("telnet delimit test 1.0"); // so I can keep track of what is loaded
myservoa.attach(6); //the pin for the servoa control
myservob.attach(7); //the pin for the servob control
myservoc.attach(8); //the pin for the servoc control
myservod.attach(9); //the pin for the servod control
Serial.println("multi-servo-telnet-delimit-test 3-12-12"); // so I can keep track of what
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
void loop()
{
// if an incoming client connects, there will be bytes available to read:
EthernetClient client = server.available();
if (client == true) {
char c = client.read(); //gets one byte from serial buffer
if (c == ',') {
if (readString.length() >1) {
//do stuff with the captured readString
Serial.println(readString); //prints string to serial port out
//server.println(readString);
client.println(readString);
int n = readString.toInt(); //convert readString into a number
Serial.print("writing servo angle: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.write(n);
if(readString.indexOf('b') >0) myservob.write(n);
if(readString.indexOf('c') >0) myservoc.write(n);
if(readString.indexOf('d') >0) myservod.write(n);
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
//server.write(c);
}
}
}
The EthernetServer.available() returns a client object only if the client has some characters available. You have to edit your EthernetServer class and insert a new method like this (quick hack, untested code):