Hello guys,
Something terrible happened. My PC got crashed and almost lost all the files and softwares... Trying to get back into track for both Safe & Sound and Upcycle Challenges. Well for Upcycle I do have some stuffs in my tablet, worried about the Safe and Sound. 
Here comes this week's write up.. All about using eSpeak utility and trying to get mail and weather updates.
Carmelito Andrade has written a nice blog on setting up USB sound card and using eSpeak to get weather update using the Open Weather map API.
The setup
Circuit
If you need something Regarding the Amplifier connections Just check my previous blog.For now its plugged into the USB sound card.
The Code: Its actually 4 scripts, 1- Arduino and 3-Python. The Arduino program checks for Button Presses and calls the python scripts.
one of the scripts is for Unread Gmail count using IMAP, the other is for getting weather updates and the last is just to play a Intro music. I'm also looking for nice API that could fetch interesting facts in random.
The Arduino Code
int a,b;
void setup() {
pinMode(11,INPUT);
pinMode(12,INPUT);
system("python /intro.py"); //Command to call python script for the Linux
}
void loop() {
delay(100);
a=digitalRead(11);
b=digitalRead(12);
delay(100);
if(a==1)
{
system("python /gmail.py");
}
if(b==1)
{
system("python /weather.py");
}
}
intro.py
import subprocess subprocess.check_output(['aplay','/media/storage/Opening.wav']) #path of Audio File
gmail.py
import subprocess
def gmail_checker(username,password):
import imaplib,re
i=imaplib.IMAP4_SSL('imap.gmail.com')
try:
i.login(username,password)
x,y=i.status('INBOX','(MESSAGES UNSEEN)')
unseen=str(re.search('UNSEEN\s+(\d+)',y[0]).group(1))
return (messages,unseen);
except:
return False,0
messages,unseen=gmail_checker('sakthi.1260@gmail.com','********') # your Gmail ID and Password
#print "%s messages, %s unseen" %(messages,unseen)
report = 'You have '+unseen+' un read e mails chief' #thought it would be better if it calls me Chief
subprocess.check_output(['espeak',report])
weather.py something similar to Carmelito Andrade's one,with a slight modification, to say "It's a hot day Chief" when temperature exceeds 28°C, need to improvise it to make it tell "Don't forget your Umbrella chief", if the forecast says its gonna rain.
import subprocess
import pyowm
import time
area = 'Chennai,IN'
key = 'xxxxxxxxxxxxxxxxxxx'
owm = pyowm.OWM(key)
obs=owm.weather_at_place(area)
w=obs.get_weather()
temp = w.get_temperature('celsius')['temp']
humidity = w.get_humidity()
report = 'The temperatur is' + str(temp) + 'degree Celsisus and Humidity is' + str(humidity) + 'Percenage'
subprocess.check_output(['espeak',report])
if temp > 28:
subprocess.check_output(['espeak','Its a hot day Chief'])Probaby if are the Batman, you can make it say "Master Bruce" instead of Chief 
So after uploading the Arduino program don't expect it to call the python scripts, no its not gonna happen, seems to be a unsolved problem .
But if I run the script from the Linux side it works, the arduino sketch gets saved as sketch.elf,in /sketch directory.
just run it using the
/sketch/sketch.elf /dev/pts/0&





Top Comments