Chapter 9

From IPRE Wiki
Revision as of 16:04, 29 May 2007 by Admin (Talk | contribs) (Sending Email)

Jump to: navigation, search

Communication

Who ya gonna call?
-: Ray Parkey, Jr. in the song Ghostbusters.

Your robot doesn't have a direct way of communicating with another robot. But it can communicate with your computer, and your computer can communicate with other computers. There are many ways that one computer can send a message to another computer, for example email. If you wanted to carry on a conversation, email is a bit slow. But one could also use instant messaging, or IM for short.

Myro contains an IM interface so that you can write programs that send and receive messages. To test this out, you can try this with a friend. First you will need to log into the IM server with a name and a password. You can make both of these up, but you should remember the password/ID pair. If you forget, you will need to make up a new pair. Also, you will need to know the ID of the person that you want to send a message to.

First, let's begin by making a Chat object:

>>> chat = Chat("myname", "mypassword")
>>> chat.send("somebodyelse", "Hi, how are you?")
>>> chat.receive()
[("sombodyelse@myro.roboteducation.org", "I'm fine, thanks!")]

Remote Robot Control

The robot that will be controlled:

>>> robot.initializeRemoteControl("mypassword")
>>> robot.processRemoteControl()
>>> []
>>> robot.processRemoteControlLoop() # threaded, infinite loop
>>> 

The computer that will be the controller:

>>> chat = Chat("myname", "mypassword")
>>> chat.send("remoterobotname", "robot.turnLeft(.4)")
>>> chat.receive() 

There is also a RemoteRobot constructor which acts like a regular robot, but sends the commands to the other robot.

>>> robot = RemoteRobot("remoterobotname")
>>> robot.turnLeft(.4)

Sending Email

In order to send mail, you'll need to know your Simple Mail Transport Protocol (SMTP) server name. At Bryn Mawr College, it is smtp.brynmawr.edu.

First, import the smtplib Python library:

>>> import smtplib

Then, you can make an SMTP object:

>>> s = smtplib.SMTP("smtp.brynmawr.edu")

And then use it to send mail. sendmail() takes three arguments: a from address, a list of recipient email addresses, and a text message.

>>> s.sendmail("yourid@brynmawr.edu", ["mom@aol.com", "dad@gmail.com", "sis@hotmail.com"], "Hi! Send money!")
{}

This example will send the same message to three people, mom, dad and sis. If you want to put line breaks in your message, you'll need to use the \n (backslash followed by a small n).

(There are a few reasons while your email might not go through. For one, this could be flagged as "spam". Because email is this easy to send to millions of people at once, some have taken advantage of this fact to send unsolicited email, aka spam. Some installations might prevent email to come from any random computer without a special password. Check with your TA for details about your site.)


Previous Chapter: Chapter 8, Up: Introduction to Computer Science via Robots, Next Chapter: Chapter 10