I'm trying to check the number of unread Mails with an Arduino+Ethernet Shield, sending two IMAP-requests. With client.read(server_answer), I store it into a char. When I send it to serial with Serial.print(server_answer), I get the following:
* OK IMAP server ready H migmx111 92345
0 OK LOGIN completed
* STATUS INBOX (UNSEEN 1)
0 OK STATUS completed
* STATUS INBOX (MESSAGES 1917)
0 OK STATUS completed
* BYE Server logging out
0 OK LOGOUT completed
Now my question: How can I extract the two numbers (total count of mails and unread mails, in the example 1 unread and 1917 total count)? How can I get them in two different strings? I want to display the numbers with some some text ("You have [number] new mails!") on a LCD.
If it helps, here's interesting part of my code:
void loop()
{
updateClient();
checkAvail();
}
void updateClient()
{
if ((millis() - updateTimer) > 10000)
{
Ethernet.begin(mac, ip);
// Serial.println("connecting...");
delay(1000);
if (client.connect())
{
//Serial.println("connected");
client.println("0 login myusername mypasswd");
client.println("0 STATUS INBOX (UNSEEN)");
client.println("0 STATUS INBOX (MESSAGES)");
client.println("0 logout");
clientConnected = true;
}
else
{
Serial.println("connection failed");
}
updateTimer = millis();
}
}
void checkAvail()
{
if (clientConnected)
{
if (client.available())
{
server_answer = client.read();
Serial.print(server_answer);
}
if (!client.connected())
{
Serial.println();
// Serial.println("disconnecting.");
client.stop();
clientConnected = false;
}
}
}