I'm sending data from an Atom feed from a python script to my Arduino board. I can succesfully communicate with the board the first time, but afterwards, I get a serial exception error from the pySerial module.
Here is my python code:
import serial, sys, feedparser
#Settings
USERNAME = "user"
PASSWORD = "pw"
PROTO = "https://"
SERVER = "gmail.google.com"
PATH = "/gmail/feed/atom"
SERIALPORT = "\\\\.\\COM6"
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
print "failed to write to port %s" % SERIALPORT
sys.exit()
newmail = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH) ["feed"]["fullcount"])
print newmail
ser.write(newmail)
ser.close()
Again, I can send a successful message to my board the first time, but afterwards it fails to the exception.
Here is my code for the Arduino board acting as a pseudo-server.
int led = 13;
int mail = LOW;
int val;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.flush();
}
void loop()
{
if (Serial.available()>0)
{
val=Serial.read();
Serial.println(val);
if(val > 0)
digitalWrite(led, HIGH);
else
digitalWrite(led, LOW);
}
}
Is there something I need to do at the end of the Serial communication in the Arduino board to reset communications? If I physically reset the Arduino board I can again send another write to the board, but not otherwise. Any suggestions?