
Dependencies: NetServices mbed
Revision 0:10508306e920, committed 2010-11-28
- Comitter:
- segundo
- Date:
- Sun Nov 28 00:43:18 2010 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 10508306e920 NetServices.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NetServices.lib Sun Nov 28 00:43:18 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/segundo/code/NetServices/#d64fca63b94e
diff -r 000000000000 -r 10508306e920 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Nov 28 00:43:18 2010 +0000 @@ -0,0 +1,75 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "NTPClient.h" +#include "SMTPClient.h" + +#define HOSTNAME "mbedSE" + +// server is domain name eg. mail.authsmtp.com +// port is smtp port eg. 25 or 23 +// domain must be acceptable to server (but often is not strictly enforced since does not affect FROM address) +#define SERVER "server" +#define PORT 25 +#define USER "username" +#define PASSWORD "password" +#define DOMAIN "mailnull.com" +#define FROM_ADDRESS "segundo.smtpclient@mailnull.com" +#define TO_ADDRESS "segundo.smtpclient@mailnull.com" + +EthernetNetIf eth(HOSTNAME); +DigitalOut led1(LED1, "led1"); + +int main() { + + printf("\n\n/* Segundo Equipo SMTPClient library demonstration */\n"); + printf("Make sure you have modified the SERVER, PORT etc in the source code\n"); + + EthernetErr ethErr; + int count = 0; + do { + printf("Setting up %d...\n", ++count); + ethErr = eth.setup(); + if (ethErr) printf("Timeout\n", ethErr); + } while (ethErr != ETH_OK); + + printf("Connected OK\n"); + const char* hwAddr = eth.getHwAddr(); + printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n", + hwAddr[0], hwAddr[1], hwAddr[2], + hwAddr[3], hwAddr[4], hwAddr[5]); + + IpAddr ethIp = eth.getIp(); + printf("IP address : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]); + + NTPClient ntp; + printf("NTP setTime...\n"); + Host server(IpAddr(), 123, "pool.ntp.org"); + printf("Result : %d\n", ntp.setTime(server)); + + time_t ctTime = time(NULL); + printf("\nTime is now (UTC): %d %s\n", ctTime, ctime(&ctTime)); + + Host host(IpAddr(), PORT, SERVER); + SMTPClient smtp(host, DOMAIN, USER, PASSWORD, SMTP_AUTH_PLAIN); + + EmailMessage msg; + msg.setFrom(FROM_ADDRESS); + msg.addTo(TO_ADDRESS); + msg.printf("Subject: mbed SMTPClient test at %s", ctime(&ctTime)); + msg.printf("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n"); + msg.printf(".\r\n"); + msg.printf("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n"); + + printf("Send result %d\n", smtp.send(&msg)); + printf("Last response | %s", smtp.getLastResponse().c_str()); + + Timer tm; + tm.start(); + + while (true) { + if (tm.read() > 0.5) { + led1 = !led1; + tm.start(); + } + } +} \ No newline at end of file
diff -r 000000000000 -r 10508306e920 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Nov 28 00:43:18 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e