Last active
August 29, 2015 13:57
-
-
Save carlynorama/9862609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//detivative of code posted here: https://www.sparkfun.com/news/1360 | |
//discussion of project here: http://blog.carlynorama.com/tag/intelgalileo/ | |
//RELEVANT CHANGES FROM OC COMMENTED IN ALL CAPS | |
int getEmailCount() | |
{ | |
//SAME VARIABLES | |
int digits = 0; | |
char temp[10]; | |
int emailCnt = 0; | |
// Send a system call to run our python script and route the | |
// output of the script to a file. | |
//ADDED ERROR MESSAGE LOG | |
//MADE THE FILE I WAS WRITING TO A .TXT FILE | |
//ADDED ERROR MESAGES LOG | |
system("python /media/realroot/pyMailCheck.py > /media/realroot/emails.txt 2>pyMailErrors.log"); | |
// Check to see if the file exists: | |
//ADDED IF FILE EXISTS CHECK | |
if (SD.exists("emails.txt")) { | |
//Serial.println("emails exists."); | |
File emailsFile = SD.open("emails.txt"); // open emails for reading | |
if (emailsFile) { | |
while ((emailsFile.available()) && (emailsFile.peek() != '\n')) { | |
//digits++ is acting like i++, it will go up every time. Assumes no bigger than 10 digit number | |
//digits is incremented AFTER it is used. | |
temp[digits++] = emailsFile.read(); | |
} | |
//digits now contains the index number of the next empty place | |
//THIS IS WHERE I ADDED THE NULL TERMINATION | |
temp[digits] = NULL; | |
//Serial.print("digits: "); | |
//Serial.println(digits); | |
//Serial.print("temp: "); | |
//Serial.println(temp); | |
//REPLACE THE FOR LOOPING WITH RUNNING atoi() ON THE CHAR ARRAY. | |
//THE FOR LOOPS ARE FRIENDLIER B/C atoi() IS NOT IN THE ARDUINO DOCS | |
emailCnt = atoi(temp); | |
emailsFile.close(); | |
} | |
// if the file isn't open, pop up an error: | |
else { | |
//TELL ME ABOUT THE PROBLEMS | |
Serial.println("error with emailsFile.txt"); | |
} | |
} | |
else { | |
//ALERT THAT SOMETHING WENT WRONG WITH THE PYTHON | |
Serial.println("emails doesn't exist."); | |
} | |
return emailCnt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment