C# Gmail Notification

Hi Everyone,

Can you help me... I have been trying to create this notifier wherein the led would light up once there is an unread mail in my gmail account. The C# code seems to be working but it seems that it doesn't communicate well with my arduino.. Not sure exactly what the problem is... I would really appreciate it if someone gives me a hand here... Thanks...

Attached are the codes...

arduino_gmail.txt (477 Bytes)

C# code gmail notif.cs (2.98 KB)

You don't explain what is working and what isn't so it's hard to help you, but:

digitalWrite(ledPin, LOW);

Maybe replace "LOW" with "mail" ?..

Hi,

The C# script, i think works just fine... It shows how many unread message I have and all.. But it doesn't seem to trigger the led in the arduino (lights up if there is an unread mail). Let me try your suggestion. :slight_smile:

Tried changing LOW to mail... still nothing though :frowning:

Could you explain what this piece of code is intended to do?

unread = checkmail(); 
for(int i=1; i>0; i++) 
{ 
    unread = checkmail(); 
    Console.WriteLine("Unread Mails: " + unread); 
    Console.WriteLine("Checking again..."); 
    port.Write("m"); 
} 
port.Write("n"); 
Console.WriteLine("Unread Mails: " + unread);

its just an infinite loop... it constantly checks the mail if there are any updates ...

its just an infinite loop... it constantly checks the mail if there are any updates ...

Then, why are there no comments to that effect? The code looks like a mistake, the way it's written.

You write m to the part on every pass through that loop, whether there is mail or not. Why? How is the Arduino supposed to distinguish between an m that means no mail and one that means mail?

refactored your arduino code a bit

const int ledPin = 9;

void setup() 
{
  pinMode(ledPin, OUTPUT);      
  Serial.begin(9600);
}

void loop()
{
  /* loop gmail check mails */
  if (Serial.available() > 0)
  {
    int val = Serial.read();
    Serial.write(val, DEC);

    if (val == 'n')
    { 
      digitalWrite(ledPin, LOW);
    } 
    else if (val == 'm')
    { 
      digitalWrite(ledPin, HIGH);
    }   
  }
  delay(5000);
}

shadow1121:
its just an infinite loop... it constantly checks the mail if there are any updates ...

... and then does what?

shadow1121:
its just an infinite loop... it constantly checks the mail if there are any updates ...

it is not an infinite loop, after 32768 times it will exit as the int overflows...

robtillaart:

shadow1121:
its just an infinite loop... it constantly checks the mail if there are any updates ...

it is not an infinite loop, after 32768 times it will exit as the int overflows...

So it's an infinite loop with a bug in it :wink:

Was actually going to say there is no need to increment i in the loop and that it would lead to an overflow but you got in before me . :slight_smile:

it is not an infinite loop, after 32768 times it will exit as the int overflows...

I think that, on the PC, it will take a few more iterations than that.

PaulS:

it is not an infinite loop, after 32768 times it will exit as the int overflows...

I think that, on the PC, it will take a few more iterations than that.

oops :slight_smile:

Please help guys.. Or if u know an easier method to do a gmail notification like this.. . Badly need.. any help would do.. . I tried several methods i found googling but having no luck.. Im pretty much a beginner to this

Did you try robtillaart's version?

wildbill:
Did you try robtillaart's version?

No sir.. Where can i find details about it?

shadow1121:
Please help guys.

The code you're running on the PC is obviously broken. Have you read the comments about it and tried addressing them? If so, where's your updated code?

shadow1121:

wildbill:
Did you try robtillaart's version?

No sir.. Where can i find details about it?

He posted a refactored version earlier in the thread.

robtillaart:
refactored your arduino code a bit

const int ledPin = 9;

void setup()
{
  pinMode(ledPin, OUTPUT);     
  Serial.begin(9600);
}

void loop()
{
  /* loop gmail check mails */
  if (Serial.available() > 0)
  {
    int val = Serial.read();
    Serial.write(val, DEC);

if (val == 'n')
    {
      digitalWrite(ledPin, LOW);
    }
    else if (val == 'm')
    {
      digitalWrite(ledPin, HIGH);
    }   
  }
  delay(5000);
}

Tried this one but I am getting some error:

sketch_aug28a.ino: In function 'void loop()':
sketch_aug28a:15: error: invalid conversion from 'int' to 'const uint8_t*'
sketch_aug28a:15: error: initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'

replace
Serial.write(val, DEC);
=>
Serial.print(val, DEC);