Some basic telnet/client code attached from other example. The return outputs all the characters received after the '-' is detected but I'm not sure how to capture specific lines within this data. Telnet data consists of 34 characters wide by 9 lines long (basic text). I just want to capture the line that begins with "RX" and send it out to another serial port.....any help would be great!
Gus.
#include <Ethernet.h>
#include <SPI.h>
byte ip[] = { 192, 168, 1, x }; //ip address (arduino)
byte server[] = {192,168,1,x}; //ip Address of the server
byte subnet[] = { 255, 255, 255, 0 };
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Client client(server, 23);
////////////////////////////////////////////////////
char inString[400]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false;
void setup(){
Ethernet.begin(mac, ip);
Serial.begin(9600);
}
void loop(){
String pageValue = connectAndRead(); //connect to the server and read the output
Serial.println(pageValue); //print out the findings.
delay(2000); //wait 2 seconds before connecting again
}
String connectAndRead(){
//connect to the server
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.print("menu1");
delay(10);
client.print("menu2");
delay(10);
client.print("status");
//Connected - Read the page
return readPage(); // read the output
}else{
return "connection failed";
}
}
String readPage(){
//read the page, and capture & return everything between '-' and '['
stringPos = 0;
memset( &inString, 0, 402); //clear inString memory
while(true){
if (client.available()) {
char c = client.read();
if (c == '-') { //'-' is our begining character
startRead = true; //Ready to start reading
}else if(startRead){
if(c != '['){ //'[' is our ending character
inString[stringPos] = c;
stringPos ++;
}else{
//got what we need - We can disconnect now
startRead = false;
client.stop();
client.flush();
Serial.println("disconnecting.");
return inString;
}
}
}
}
}