Paso 3: Subir archivos
1. encontrar a una dirección de IP de Galileos
- Subir el archivo getIP.ino con el IDE de Arduino en el Galileo y ejecutarlo
- No te olvides de conectar el cable Ethernet ;)
- Abrir el "Serial Monitor" [STRG + Mayús + M] y establecer la velocidad en baudios de 9600
2. subir los archivos
Windows:
- Descargar e instalar Winscp
- Cargar el archivo weather.py en / home/root/en el Galileo
- Hacer lo mismo con el config.txt y mail.py
Linux:
- Tipo
scp /path/to/your/file/weather.py root /path/to/your/file/config.txt root
en tu consola
Weather.py:
#!/bin/python2.7import sys import urllib2 import xml.etree.ElementTree as ETif (len(sys.argv) <= 1): # No arguments given. So we use Aachen as default place city = "Aachen" else: # Otherwise the given city city = sys.argv[1]# Download from openweathermap the current weather as xml try: response = urllib2.urlopen('http://api.openweathermap.org/data/2.5/weather?q='+city+'&mode=xml&units=metric&lang=de', timeout = 10) except urllib2.URLError: # On timeout stop script and return error sys.exit(-1)# Init the xml parser with our downloaded text root = ET.fromstring(response.read())# Find out some intresting values temp = root.find('temperature').get('value') clouds = root.find('clouds').get('value')# precipitation is a bit dificult. Either it is set to no ... if (root.find('precipitation').get('mode') == "no"): rain = 0 else: # ... ore a value is given rain = root.find('precipitation').get('value')# Now we pint our parsed values, so it is posible to read them out of # the Arduino sketch print temp print clouds print rain
mail.py
#!/bin/python2.7import sys import smtplib# Do some config here SMTPServerUrl = 'www.host.com' SMTPServerPort = 25 SMTPUsername = 'username' SMTPPassword = 'password' EmailAddress = 'your.mail SUBJECT = 'Weather information'# Check given parameters if (len(sys.argv) <= 2): print "Usage: [target mail addr.] [message]" sys.exit(-1)# Next try to connect to the server try: server = smtplib.SMTP(SMTPServerUrl, SMTPServerPort) server.login(SMTPUsername, SMTPPassword) except: # Print some error messages print "Error Connecting" sys.exit(-1)# Now try to send our given Message try: message = "Subject: " + SUBJECT + "\n" + sys.argv[2] server.sendmail(EmailAddress, sys.argv[1], message) except: # Print some error messages print "Error Sending" sys.exit(-1)# Finally disconnect server.quit()
config.txt:
AachenAachen;0;30;0;100;1;100;It is raining. Take a umbrella with you.;your.mail Aachen;18;30;0;33;0;0;The weather is sunny. You can leave your jacket at home.;your.mail
getIP.ino:
void setup() { // Set the baud rate Serial.begin(9600); } void loop() { // Execute ifconfig and pipe everything to the serial output system("ifconfig &> /dev/ttyGS0"); // Wait some time sleep(5); }