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_Ethernet_Example by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "TCPSocketConnection.h" 00004 00005 EthernetInterface eth; 00006 RawSerial pc(USBTX, USBRX); // tx, rx 00007 00008 int main() 00009 { 00010 pc.baud(9600); 00011 eth.init(); //Use DHCP 00012 eth.connect(); 00013 printf("IP Address is %s \n\r", eth.getIPAddress()); 00014 TCPSocketConnection socket; 00015 00016 socket.connect("maker.ifttt.com", 80); 00017 00018 /*char eventName[]="OWJMAN"; 00019 char secretKey[]="bkJhw8soKcjx28zrqAgeW2"; 00020 const char * v1="sdasd"; 00021 const char * v2="sdad"; 00022 const char * v3="gklj"; 00023 char str[512] = {0}; 00024 char header[150] = {0}; 00025 sprintf(header, "POST /trigger/%s/with/key/%s HTTP/1.1\r\n",eventName,secretKey); 00026 const char * host = "Host: maker.ifttt.com\r\n"; 00027 char contentLen[50] = {0}; 00028 const char * contentType = "Content-Type: application/json\r\n\r\n"; 00029 char valueData [150] = {0}; 00030 sprintf(valueData,"{\"value1\":\"%s\",\"value2\":\"%s\",\"value3\":\"%s\"}\r\n",v1,v2,v3); 00031 sprintf(contentLen,"Content-Length: %d\r\n",strlen(valueData)); 00032 sprintf(str,"%s%s%s%s%s",header,host,contentLen,contentType,valueData); 00033 printf("%s\n",str);*/ 00034 char *post = "POST /trigger/OWJMAN/with/key/bkJhw8soKcjx28zrqAgeW2 HTTP/1.1\r\n"; 00035 char *host = "Host: maker.ifttt.com\r\n"; 00036 char *type = "Content-Type: application/json\r\n\r\n"; 00037 char contentLen[] = ""; 00038 char *data = "{\"value1\":\"asdasdasd\",\"value2\":\"asdasdasd\",\"value3\":\"fffff\"}\r\n"; 00039 sprintf(contentLen,"Content-Length: %d\r\n",strlen(data)); 00040 socket.send_all(post, strlen(post)); 00041 socket.send_all(host, strlen(host)); 00042 socket.send_all(contentLen, strlen(contentLen)); 00043 socket.send_all(type, strlen(type)); 00044 socket.send_all(data, strlen(data)); 00045 printf("%s%s%s%s%s",post,host,contentLen,type,data); 00046 00047 char buffer[300]; 00048 int ret; 00049 while (true) { 00050 ret = socket.receive(buffer, sizeof(buffer)-1); 00051 if (ret <= 0) 00052 break; 00053 buffer[ret] = '\0'; 00054 printf("Received %d chars from server:\n%s\n", ret, buffer); 00055 } 00056 printf("DONE!\n"); 00057 00058 socket.close(); 00059 00060 eth.disconnect(); 00061 00062 while(1) {} 00063 } 00064 extern "C" void mbed_mac_address(char *mac) 00065 { 00066 mac[0] = 0xD4; 00067 mac[1] = 0x3F; 00068 mac[2] = 0x7E; 00069 mac[3] = 0x4C; 00070 mac[4] = 0x7E; 00071 mac[5] = 0x1C; 00072 };
Generated on Fri Jul 29 2022 14:01:44 by
1.7.2
