Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of IFTTT_Done by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "TCPSocketConnection.h" 00004 00005 const char cip[] = "192.168.10.89"; 00006 const char cmask[] = "255.255.255.0"; 00007 const char cgateway[] = "192.168.10.202"; 00008 00009 EthernetInterface eth; 00010 RawSerial pc(USBTX, USBRX); // tx, rx 00011 00012 00013 int main() 00014 { 00015 pc.baud(9600); 00016 00017 pc.printf("\n"); 00018 pc.printf("\n"); 00019 pc.printf("--------------------------------\n"); 00020 pc.printf("Program starts ...\n"); 00021 //eth.init(); //Use DHCP 00022 00023 // fix ip address 00024 00025 int init_rtn = eth.init(cip, //const char * ip, 00026 cmask, //const char * mask, 00027 cgateway //const char * gateway 00028 ); 00029 00030 pc.printf("init() return : %d\n", init_rtn); 00031 00032 pc.printf("\n"); 00033 pc.printf(" wait for ethernet connect()......\n"); 00034 pc.printf("\n"); 00035 00036 // eth.connect(); 00037 int connect_rtn = eth.connect(); 00038 pc.printf("connect() return : %d\n", connect_rtn); 00039 00040 printf("IP Address is %s \n\r", eth.getIPAddress()); 00041 00042 pc.printf("IP Address is %s\n", eth.getMACAddress()); 00043 pc.printf("\n"); 00044 00045 00046 TCPSocketConnection socket; 00047 00048 int isocket_connect = socket.connect("maker.ifttt.com", 80); 00049 pc.printf("socket connectted... %d\n", isocket_connect); 00050 00051 /* 00052 char str[]=""; 00053 char *post = "POST /trigger/OWJMAN/with/key/bkJhw8soKcjx28zrqAgeW2 HTTP/1.1\r\n"; 00054 char *host = "Host: maker.ifttt.com\r\n"; 00055 char *type = "Content-Type: application/json\r\n\r\n"; 00056 char contentLen[50] = {0}; 00057 char *data = "{\"value1\":\"this is awesome\",\"value2\":\"test-ing\",\"value3\":\"data!!!\"}\r\n"; 00058 sprintf(contentLen,"Content-Length: %d\r\n",strlen(data)); 00059 sprintf(str,"%s%s%s%s%s",post,host,contentLen,type,data); 00060 socket.send_all(str, strlen(str));*/ 00061 00062 char *post = "POST /trigger/helloworld/with/key/brbeSCjegrJbPkzvV-v0uc HTTP/1.1\r\n"; 00063 char *host = "Host: maker.ifttt.com\r\n"; 00064 char *type = "Content-Type: application/json\r\n\r\n"; 00065 char contentLen[] = ""; 00066 char *data = "{\"value1\":\"this is awesome\",\"value2\":\"test-ing\",\"value3\":\"data!!!\"}\r\n"; 00067 00068 sprintf(contentLen,"Content-Length: %d\r\n",strlen(data)); 00069 00070 int i_post, i_host, i_type, i_content, i_data; 00071 00072 pc.printf("Post: %s", post); 00073 i_post = socket.send_all(post, strlen(post)); 00074 pc.printf("Post: %d\n", i_post); 00075 00076 pc.printf("Host: %s", host); 00077 i_host = socket.send_all(host, strlen(host)); 00078 pc.printf("Host: %d\n", i_host); 00079 00080 pc.printf("Type: %s", type); 00081 i_type = socket.send_all(type, strlen(type)); 00082 pc.printf("Type: %d\n", i_type); 00083 00084 pc.printf("Content length: %s", contentLen); 00085 i_content = socket.send_all(contentLen, strlen(contentLen)); 00086 pc.printf("Content: %d\n", i_content); 00087 00088 pc.printf("Data: %s", data); 00089 i_data = socket.send_all(data, strlen(data)); 00090 pc.printf("Data: %d\n", i_data); 00091 00092 char buffer[600]; 00093 int ret; 00094 while (true) { 00095 ret = socket.receive(buffer, sizeof(buffer)-1); 00096 if (ret <= 0) 00097 break; 00098 buffer[ret] = '\0'; 00099 printf("Received %d chars from server:\n%s\n", ret, buffer); 00100 } 00101 printf("DONE!\n"); 00102 00103 int i_close; 00104 00105 i_close = socket.close(); 00106 pc.printf("Socket close: %d\n", i_close); 00107 00108 eth.disconnect(); 00109 00110 pc.printf("\n"); 00111 pc.printf("\n"); 00112 pc.printf("Program end....\n"); 00113 pc.printf("\n"); 00114 pc.printf("\n"); 00115 00116 while(1) {} 00117 } 00118 extern "C" void mbed_mac_address(char *mac) 00119 { 00120 mac[0] = 0x00; 00121 mac[1] = 0x50; 00122 mac[2] = 0x56; 00123 mac[3] = 0xC0; 00124 mac[4] = 0x00; 00125 mac[5] = 0xAB; 00126 };
Generated on Tue Jul 19 2022 04:55:34 by
1.7.2
