Hardware Reference
In-Depth Information
four messages are used. The user was warned, wasn't he? Well, in that case, the
plant has the right to insist a little more by sending some different messages.
Finally, the client sends a message informing the SMTP server that it has sent
all the data required and then quits. The client.stop() function makes sure
that the Arduino disconnects from the SMTP server. The function then returns
true , informing the sketch that everything went well.
Exercises
The sendEmail() function sends all the required information to an SMTP server,
but SMTP servers also send information, including information that could be
useful in case of a disconnection (wrong e-mail, server full, and so on). Have a
look at the SMTP documentation, or a few examples of how SMTP servers work,
and add some functions to verify the data sent by the server. Many examples
are on the Internet, including some examples using Telnet with SMTP, which
might be a good place to start. An example of SMTP exchanges is available at
http://packetfury.net/index.php/en/Arduino/tutorials/251-smtp .
When placing a WiFi shield on the Uno, the internal LED is probably hidden.
Try adding an external LED to the device to show that an error has occurred,
and a second external LED to indicate the plant needs water.
While some SMTP servers will not require authentication, there are more and
more servers that do. This adds one additional step. A login requires three ele-
ments: the user login, the password (of course), but also a step to tell the server
what type of authentication you are requesting. The most common authentica-
tion is LOGIN. The server will request a simple login and password. To request
a LOGIN authentication, you must send a new line:
auth login
The server will respond with a strange line, something like this:
334 VXNlcm5hbWU6
So what is this? This is an encoded word, written in Base64. This is a way
of including special characters like accents and non-Latin letters in ASCII. You
must i rst convert your login and password to Base64, using one of the numer-
ous web pages available. You can i nd a Base64 encoder at http://packetfury
.net/index.php/en/Arduino/250-base64.php .
The exchange with the server will look like this:
Client: auth login
Server: 334 VXNlcm5hbWU6
Client: <login>
 
Search WWH ::




Custom Search