Trigger button to send email to Team members

Dependencies:   HTTPClient WIZnet_Library mbed

Fork of EmailButton by Bohyun Bang

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "WIZnetInterface.h"
00003 #include "HTTPClient.h"
00004 
00005 #define USE_DHCP    0
00006 
00007 #define LOOPBACKPORT    5000
00008 
00009 const char * IP_Addr    = "222.98.173.212";
00010 const char * IP_Subnet  = "255.255.255.192";
00011 const char * IP_Gateway = "222.98.173.254";
00012 unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56};
00013 
00014 Serial pc(USBTX, USBRX);
00015 
00016 #ifdef TARGET_LPC11U68
00017 SPI spi(P0_9,P0_8,P1_29);
00018 WIZnetInterface ethernet(&spi,P0_2,P1_13);
00019 #endif
00020 
00021 int main() {
00022 //    EthernetInterface eth;
00023 // change for W5500 interface.
00024 
00025     mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres
00026     pc.baud(115200);
00027     
00028     #if USE_DHCP
00029     int ret = ethernet.init(MAC_Addr);
00030     #else
00031     int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway);
00032     #endif
00033     if (!ret) {
00034         pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
00035         ret = ethernet.connect();
00036         if (!ret) {
00037             pc.printf("IP: %s, MASK: %s, GW: %s\r\n",
00038                       ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
00039         } else {
00040             pc.printf("Error ethernet.connect() - ret = %d\r\n", ret);
00041             exit(0);
00042         }
00043     } else {
00044         pc.printf("Error ethernet.init() - ret = %d\r\n", ret);
00045         exit(0);
00046     }
00047     
00048     char str[512];
00049     char get_msg[512]= "http://bjsnippets.appspot.com/emailbutton";
00050     HTTPClient http;
00051     
00052     pc.printf("Send Email to all team members\r\n");
00053     pc.printf("msg : %s\r\n",get_msg);
00054     ret = http.get(get_msg, str, sizeof(str));
00055     if(!ret)
00056     {
00057       pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str));
00058       pc.printf("Result: %s\r\n", str);
00059     }
00060     else
00061     {
00062       pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
00063     }
00064 
00065     /*
00066     char str1[512];
00067     char get_msg1[512]= "http://bjsnippets.appspot.com/digestemail";
00068     HTTPClient http1;
00069     
00070     pc.printf("Send get Message to openeathermap.org\r\n");
00071     pc.printf("msg : %s\r\n",get_msg1);
00072     ret = http1.get(get_msg1, str1, sizeof(str1));
00073     if(!ret)
00074     {
00075       pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str1));
00076       pc.printf("Result: %s\r\n", str1);
00077     }
00078     else
00079     {
00080       pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http1.getHTTPResponseCode());
00081     }
00082    */
00083 }