![](/media/cache/profiles/bongjun_profile_500.png.50x50_q85.jpg)
Trigger button to send email to Team members
Dependencies: HTTPClient WIZnet_Library mbed
Fork of EmailButton by
main.cpp@1:8bf7fbe91a58, 2015-04-29 (annotated)
- Committer:
- Bongjun
- Date:
- Wed Apr 29 01:24:51 2015 +0000
- Revision:
- 1:8bf7fbe91a58
- Parent:
- 0:296b140c37e2
#1st Example for EmailButton
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bangbh | 0:296b140c37e2 | 1 | #include "mbed.h" |
bangbh | 0:296b140c37e2 | 2 | #include "WIZnetInterface.h" |
bangbh | 0:296b140c37e2 | 3 | #include "HTTPClient.h" |
bangbh | 0:296b140c37e2 | 4 | |
bangbh | 0:296b140c37e2 | 5 | #define USE_DHCP 0 |
bangbh | 0:296b140c37e2 | 6 | |
bangbh | 0:296b140c37e2 | 7 | #define LOOPBACKPORT 5000 |
bangbh | 0:296b140c37e2 | 8 | |
bangbh | 0:296b140c37e2 | 9 | const char * IP_Addr = "222.98.173.212"; |
bangbh | 0:296b140c37e2 | 10 | const char * IP_Subnet = "255.255.255.192"; |
bangbh | 0:296b140c37e2 | 11 | const char * IP_Gateway = "222.98.173.254"; |
bangbh | 0:296b140c37e2 | 12 | unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; |
bangbh | 0:296b140c37e2 | 13 | |
bangbh | 0:296b140c37e2 | 14 | Serial pc(USBTX, USBRX); |
bangbh | 0:296b140c37e2 | 15 | |
bangbh | 0:296b140c37e2 | 16 | #ifdef TARGET_LPC11U68 |
bangbh | 0:296b140c37e2 | 17 | SPI spi(P0_9,P0_8,P1_29); |
bangbh | 0:296b140c37e2 | 18 | WIZnetInterface ethernet(&spi,P0_2,P1_13); |
bangbh | 0:296b140c37e2 | 19 | #endif |
bangbh | 0:296b140c37e2 | 20 | |
bangbh | 0:296b140c37e2 | 21 | int main() { |
bangbh | 0:296b140c37e2 | 22 | // EthernetInterface eth; |
bangbh | 0:296b140c37e2 | 23 | // change for W5500 interface. |
bangbh | 0:296b140c37e2 | 24 | |
bangbh | 0:296b140c37e2 | 25 | mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres |
bangbh | 0:296b140c37e2 | 26 | pc.baud(115200); |
bangbh | 0:296b140c37e2 | 27 | |
bangbh | 0:296b140c37e2 | 28 | #if USE_DHCP |
bangbh | 0:296b140c37e2 | 29 | int ret = ethernet.init(MAC_Addr); |
bangbh | 0:296b140c37e2 | 30 | #else |
bangbh | 0:296b140c37e2 | 31 | int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); |
bangbh | 0:296b140c37e2 | 32 | #endif |
bangbh | 0:296b140c37e2 | 33 | if (!ret) { |
bangbh | 0:296b140c37e2 | 34 | pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); |
bangbh | 0:296b140c37e2 | 35 | ret = ethernet.connect(); |
bangbh | 0:296b140c37e2 | 36 | if (!ret) { |
bangbh | 0:296b140c37e2 | 37 | pc.printf("IP: %s, MASK: %s, GW: %s\r\n", |
bangbh | 0:296b140c37e2 | 38 | ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); |
bangbh | 0:296b140c37e2 | 39 | } else { |
bangbh | 0:296b140c37e2 | 40 | pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); |
bangbh | 0:296b140c37e2 | 41 | exit(0); |
bangbh | 0:296b140c37e2 | 42 | } |
bangbh | 0:296b140c37e2 | 43 | } else { |
bangbh | 0:296b140c37e2 | 44 | pc.printf("Error ethernet.init() - ret = %d\r\n", ret); |
bangbh | 0:296b140c37e2 | 45 | exit(0); |
bangbh | 0:296b140c37e2 | 46 | } |
bangbh | 0:296b140c37e2 | 47 | |
bangbh | 0:296b140c37e2 | 48 | char str[512]; |
bangbh | 0:296b140c37e2 | 49 | char get_msg[512]= "http://bjsnippets.appspot.com/emailbutton"; |
bangbh | 0:296b140c37e2 | 50 | HTTPClient http; |
bangbh | 0:296b140c37e2 | 51 | |
Bongjun | 1:8bf7fbe91a58 | 52 | pc.printf("Send Email to all team members\r\n"); |
bangbh | 0:296b140c37e2 | 53 | pc.printf("msg : %s\r\n",get_msg); |
bangbh | 0:296b140c37e2 | 54 | ret = http.get(get_msg, str, sizeof(str)); |
bangbh | 0:296b140c37e2 | 55 | if(!ret) |
bangbh | 0:296b140c37e2 | 56 | { |
bangbh | 0:296b140c37e2 | 57 | pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); |
bangbh | 0:296b140c37e2 | 58 | pc.printf("Result: %s\r\n", str); |
bangbh | 0:296b140c37e2 | 59 | } |
bangbh | 0:296b140c37e2 | 60 | else |
bangbh | 0:296b140c37e2 | 61 | { |
bangbh | 0:296b140c37e2 | 62 | pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
bangbh | 0:296b140c37e2 | 63 | } |
bangbh | 0:296b140c37e2 | 64 | |
bangbh | 0:296b140c37e2 | 65 | /* |
bangbh | 0:296b140c37e2 | 66 | char str1[512]; |
bangbh | 0:296b140c37e2 | 67 | char get_msg1[512]= "http://bjsnippets.appspot.com/digestemail"; |
bangbh | 0:296b140c37e2 | 68 | HTTPClient http1; |
bangbh | 0:296b140c37e2 | 69 | |
bangbh | 0:296b140c37e2 | 70 | pc.printf("Send get Message to openeathermap.org\r\n"); |
bangbh | 0:296b140c37e2 | 71 | pc.printf("msg : %s\r\n",get_msg1); |
bangbh | 0:296b140c37e2 | 72 | ret = http1.get(get_msg1, str1, sizeof(str1)); |
bangbh | 0:296b140c37e2 | 73 | if(!ret) |
bangbh | 0:296b140c37e2 | 74 | { |
bangbh | 0:296b140c37e2 | 75 | pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str1)); |
bangbh | 0:296b140c37e2 | 76 | pc.printf("Result: %s\r\n", str1); |
bangbh | 0:296b140c37e2 | 77 | } |
bangbh | 0:296b140c37e2 | 78 | else |
bangbh | 0:296b140c37e2 | 79 | { |
bangbh | 0:296b140c37e2 | 80 | pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http1.getHTTPResponseCode()); |
bangbh | 0:296b140c37e2 | 81 | } |
bangbh | 0:296b140c37e2 | 82 | */ |
bangbh | 0:296b140c37e2 | 83 | } |