Sorry about the confusing topic. Please bear with me while I type out my background information/include screenshots.
Alright, so I wrote a python program to check my email, and categorize them according to author: uncategorized, Facebook Notifications, or Twitter Notifications. Next, it tries to send this information over serial to my Arduino. On the arduino end, however, nothing seems to happen... I can see the pin 13 LED light up as the serial port opens, (I think that's what is happening) then nothing.
import feedparser, requests, serial, sys
b = feedparser.parse(requests.get('https://mail.google.com/mail/feed/atom', auth=('gmailusername', 'gmailpassword')).content)
SERIALPORT = "COM3"
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
sys.exit()
mailcount = int(b['feed']['fullcount'])
facebook = int(0)
twitter = int(0)
print("Total mail: " + b['feed']['fullcount'])
if mailcount > 0:
for entry in b['entries']:
author = (entry['author'])
if "postmaster.twitter.com" in author:
twitter += 1
mailcount -= 1
if "facebookmail.com" in author:
facebook += 1
mailcount -= 1
print("Uncategorized mail: " + str(mailcount))
print("Facebook mail: " + str(facebook))
print("Twitter mail: " + str(twitter))
if mailcount > 0: ser.write(bytes('7', encoding='ascii'))
else: ser.write(bytes('MN', encoding='ascii'))
if facebook > 0: ser.write(bytes('FY', encoding='ascii'))
else: ser.write(bytes('FN', encoding='ascii'))
if twitter > 0: ser.write(bytes('TY', encoding='ascii'))
else: ser.write(bytes('TN', encoding='ascii'))
ser.close()
Screenshot of my Python code.
Screenshot of Python output.
int mailOut = 8;
int fbOut = 9;
int twitOut = 10;
int mail = LOW;
int fb = LOW;
int twit = LOW;
int val;
void setup()
{
pinMode(mailOut, OUTPUT);
pinMode(fbOut, OUTPUT);
pinMode(twitOut, OUTPUT);
Serial.begin(9600);
Serial.flush();
}
void loop()
{
if (Serial.available())
{
val = Serial.read();
Serial.println(val);
if (val == 'MY') mail = HIGH;
else if (val == 'MN') mail = LOW;
}
digitalWrite(mailOut, mail);
}
And, finally, the Arduino code. Not sure what's going on.. maybe I'm just too tired to see the blaring problem.