Hi, I'm trying to develop my own simple SMTP client code with error-handling.
I've got a mailserver running to test on. I'm also using the 28J60 with UIpethernet lib
Problem is that after a few succesfull client.read's the arduino receives 4-5 characters incorrect. I'm suspecting a memory issue.
Below snapshot of my code:
byte emailstatus=1;
char* clientreplies[]={"helo www.arduino.be","auth login","Z3JlZW5lcmd5bWFpbHRlc3RAZ3JlZW5lcmd5bWFpbHRlc3QuYmU=","U3V6dWtp","mail from:wouter@arduino.be"};
char* serverreplies[]={"220","250","334","334","235"};
String response="";
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
//Serial.write(client.available());
if (client.available()) {
char c = client.read();
Serial.print(c);
response+=c;
if (c == '\n'){
//Serial.println("end of line signal received");
//Serial.print("Response string: ");
if (response.substring(0,3) == serverreplies[emailstatus-1] && emailstatus<=5) {
client.println(clientreplies[emailstatus-1]);
Serial.println(clientreplies[emailstatus-1]);
//Serial.println(response.length());
//delay(1000);
response=""; //reset response string
emailstatus+=1;
}
}
}
// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:
//Serial.println(Serial.available());
while (Serial.available() > 0) {
/*char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
Serial.print(inChar);
//client.println("");
//client.println("");
}*/
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing:
while(true);
}
}
}
Serial monitor result:
My IP address: 192.168.0.233.connecting...
connected
220 www.greenergysolutions.be ESMTP
helo www.arduino.be
250 Hello.
auth login
334 VXNlcm5hbWU6
Z3JlZW5lcmd5bWFpbHRlc3RAZ3JlZW5lcmd5bWFpbHRlc3QuYmU=
@ à @ zc3dvcmQ6
this "@ à @ " is wrong, I couldn't even copy-paste it to here for some reason. It should be again "334....". Characters starting from zc3... are again correct though
Ideas anyone?