First you need to Install Python: Download Python | Python.org
Then you have to understand the language (but this is not Necessaray, you learn with the Programms you read)
Maybe you need the Com port here is a little Programm:
import serial
COMPORT = 8
BAUDRATE = 115200
MASSAGE = "Testnachicht"
print "Initialisiere Comport %s mit einer Baudrate von %s" % (COMPORT, BAUDRATE)
ser = serial.Serial(COMPORT, BAUDRATE, timeout=0)
print "Comport Initialisiert"
print "Sende '%s'.." % (MASSAGE)
ser.write('5')
print "...gesendet"
Important is that in this Language no ; and { exist like in Java.
My finished E-Mail Programm that checks for "Start" and sends 1 over serial and "Stop" and sends 2
# -*- coding: cp1252 -*-
import sys, getpass, poplib, re
import serial
import time
# arduino connection
COMPORT = 8
BAUDRATE = 115200
# change according to your needs
POPHOST = "popmail.t-online.de"
POPUSER = "sebastian.frebel@t-online.de"
POPPASS = raw_input("Bitte gieb dein E-Mail Passwort ein:")
# the number of message body lines to retrieve
MAXLINES = 10
HEADERS = "@Arduino".split()
print "Erwartete Header: %s" % (HEADERS)
print "Max. Zeilen: %s" % (MAXLINES)
# headers you're actually interested in
rx_headers = re.compile('|'.join(HEADERS), re.IGNORECASE)
try:
# Hauptmenüü
while 1:
# Space
print
print
print 50 * "_"
print
print
print
key = raw_input("(w=wait for Massage, o=organize Mailbox, q=quit) What?")
if key == 'w':
ser = serial.Serial(COMPORT, BAUDRATE, timeout=0)
# Anfang warten
# connect to POP3 and identify user
pop = poplib.POP3(POPHOST)
pop.user(POPUSER)
if not POPPASS or POPPASS=='=':
# if no password was supplied, ask for it
POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST))
# authenticate user
pop.pass_(POPPASS)
# get general information (msg_count, box_size)
stat = pop.stat( )
# print some information
print "Logged in as %s@%s" % (POPUSER, POPHOST)
print "Status: %d message(s), %d bytes" % stat
print "Waiting for assignment for Arduino"
# eigentliche Programm
TIME = 10
bye = 0
count_del = 0
while 1:
n = 0
for n in range(stat[0]):
msgnum = n + 1
# retrieve headers
response, lines, bytes = pop.top(msgnum, MAXLINES)
# suchen nach Begriff
#if lines.find('Stop') != -1:
#print "Stop in if gefunden!"
if 'Stop' in lines:
print "Stop Gefunden!!!"
print "Initialisiere Comport %s mit einer Baudrate von %s" % (COMPORT, BAUDRATE)
print "Comport Initialisiert"
print "Sende 1.."
ser.write('1')
print "...gesendet"
if 'Start' in lines:
print "Start Gefunden!!!"
print "Initialisiere Comport %s mit einer Baudrate von %s" % (COMPORT, BAUDRATE)
print "Comport Initialisiert"
print "Sende 2.."
ser.write('2')
print "...gesendet"
n = n + 1
n = 0
print "Status: %d message(s), %d bytes" % stat
if "start" in response:
print "Loooooooooos!"
pop.quit( )
# Waits TIMEs
time.sleep(TIME)
# headers you're actually interested in
rx_headers = re.compile('|'.join(HEADERS), re.IGNORECASE)
# connect to POP3 and identify user
pop = poplib.POP3(POPHOST)
pop.user(POPUSER)
if not POPPASS or POPPASS=='=':
# if no password was supplied, ask for it
POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST))
# authenticate user
pop.pass_(POPPASS)
# get general information (msg_count, box_size)
stat = pop.stat( )
# Ende warten
elif key == 'o':
# Anfang Organisation
# connect to POP3 and identify user
pop = poplib.POP3(POPHOST)
pop.user(POPUSER)
if not POPPASS or POPPASS=='=':
# if no password was supplied, ask for it
POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST))
# authenticate user
pop.pass_(POPPASS)
# get general information (msg_count, box_size)
stat = pop.stat( )
# print some information
print "Logged in as %s@%s" % (POPUSER, POPHOST)
print "Status: %d message(s), %d bytes" % stat
bye = 0
count_del = 0
for n in range(stat[0]):
msgnum = n+1
# retrieve headers
response, lines, bytes = pop.top(msgnum, MAXLINES)
# print message info and headers you're interested in
print "Message %d (%d bytes)" % (msgnum, bytes)
print "-" * 30
print "\n".join(filter(rx_headers.match, lines))
print "-" * 30
# input loop
while 1:
k = raw_input("(d=delete, s=skip, v=view, q=quit) What?")
#k = k[:1].lower( )
if k == 'd':
# Mark message for deletion
k = raw_input("Delete message %d? (y/n)" % msgnum)
if k in "yY":
pop.dele(msgnum)
print "Message %d marked for deletion" % msgnum
count_del += 1
break
elif k == 's':
print "Message %d left on server" % msgnum
break
elif k == 'v':
print "-" * 30
print "\n".join(lines)
print "-" * 30
elif k == 'q':
bye = 1
break
# done ...
if bye:
print "Bye"
break
# summary
print "Deleting %d message(s) in mailbox %s@%s" % (
count_del, POPUSER, POPHOST)
# close operations and disconnect from server
print "Closing POP3 session"
pop.quit( )
# Ende Organisation
elif key == 'q':
quit()
else:
print "Falsche Eingabe. Bitte versuche es nocheinmal."
except poplib.error_proto, detail:
# possible error
print "POP3 Protocol Error:", detail