Mbed to IFTTT

Dependencies:   EthernetInterface IFTTT mbed-rtos mbed

Fork of TCPSocket_Ethernet by TaChing Yu

Committer:
Jeffdhyan
Date:
Sun Sep 11 06:49:25 2016 +0000
Revision:
3:97c3e915a108
Parent:
2:807d696cf266
IFTTT_Mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yu10078999 0:ea9c19e28331 1 #include "mbed.h"
yu10078999 0:ea9c19e28331 2 #include "EthernetInterface.h"
yu10078999 1:b1506df02fe6 3 #include "TCPSocketConnection.h"
Jeffdhyan 3:97c3e915a108 4 #include "ifttt.h"
yu10078999 0:ea9c19e28331 5
yu10078999 1:b1506df02fe6 6 EthernetInterface eth;
yu10078999 1:b1506df02fe6 7 RawSerial pc(USBTX, USBRX); // tx, rx
yu10078999 1:b1506df02fe6 8
yu10078999 1:b1506df02fe6 9 int main()
yu10078999 1:b1506df02fe6 10 {
yu10078999 1:b1506df02fe6 11 pc.baud(9600);
yu10078999 1:b1506df02fe6 12 eth.init(); //Use DHCP
yu10078999 0:ea9c19e28331 13 eth.connect();
yu10078999 1:b1506df02fe6 14 printf("IP Address is %s \n\r", eth.getIPAddress());
yu10078999 1:b1506df02fe6 15 TCPSocketConnection socket;
yu10078999 0:ea9c19e28331 16
yu10078999 1:b1506df02fe6 17 socket.connect("httpbin.org", 80);
yu10078999 0:ea9c19e28331 18
yu10078999 0:ea9c19e28331 19 char http_cmd[] = "GET /get?helloworld HTTP/1.0\r\n\r\n";
yu10078999 1:b1506df02fe6 20 socket.send_all(http_cmd, sizeof(http_cmd)-1);
yu10078999 0:ea9c19e28331 21
yu10078999 0:ea9c19e28331 22 char buffer[300];
yu10078999 0:ea9c19e28331 23 int ret;
yu10078999 0:ea9c19e28331 24 while (true) {
yu10078999 1:b1506df02fe6 25 ret = socket.receive(buffer, sizeof(buffer)-1);
yu10078999 0:ea9c19e28331 26 if (ret <= 0)
yu10078999 0:ea9c19e28331 27 break;
yu10078999 0:ea9c19e28331 28 buffer[ret] = '\0';
yu10078999 0:ea9c19e28331 29 printf("Received %d chars from server:\n%s\n", ret, buffer);
yu10078999 0:ea9c19e28331 30 }
yu10078999 0:ea9c19e28331 31
yu10078999 1:b1506df02fe6 32 printf("DONE!\n");
Jeffdhyan 3:97c3e915a108 33 // Initialize ifttt object, add up to 3 optional values, trigger event.
Jeffdhyan 3:97c3e915a108 34 IFTTT ifttt("hellowordmbed","ExqSjQiwzZINRMFTOgo--", &socket); // EventName, Secret Key, socket to use
Jeffdhyan 3:97c3e915a108 35 ifttt.addIngredients("this is awesome","test-ing","data!!!"); // 3 optional Values to send along with trigger.
Jeffdhyan 3:97c3e915a108 36 ifttt.trigger();
Jeffdhyan 3:97c3e915a108 37
Jeffdhyan 3:97c3e915a108 38 // Send data using GET
Jeffdhyan 3:97c3e915a108 39 ifttt.addIngredients("Sending","GET","data");
Jeffdhyan 3:97c3e915a108 40 ifttt.trigger(IFTTT_GET);
Jeffdhyan 3:97c3e915a108 41
Jeffdhyan 3:97c3e915a108 42 // Send Data using POST
Jeffdhyan 3:97c3e915a108 43 ifttt.addIngredients("Sending","POST","things");
Jeffdhyan 3:97c3e915a108 44 ifttt.trigger(IFTTT_POST);
Jeffdhyan 3:97c3e915a108 45
Jeffdhyan 3:97c3e915a108 46
Jeffdhyan 3:97c3e915a108 47
yu10078999 1:b1506df02fe6 48 socket.close();
yu10078999 0:ea9c19e28331 49
yu10078999 0:ea9c19e28331 50 eth.disconnect();
yu10078999 0:ea9c19e28331 51
Jeffdhyan 3:97c3e915a108 52 while(1) {
Jeffdhyan 3:97c3e915a108 53 }
yu10078999 0:ea9c19e28331 54 }
yu10078999 2:807d696cf266 55 extern "C" void mbed_mac_address(char *mac)
yu10078999 2:807d696cf266 56 {
yu10078999 2:807d696cf266 57 mac[0] = 0xD4;
yu10078999 2:807d696cf266 58 mac[1] = 0x3D;
yu10078999 2:807d696cf266 59 mac[2] = 0x7E;
Jeffdhyan 3:97c3e915a108 60 mac[3] = 0x2C;
yu10078999 2:807d696cf266 61 mac[4] = 0x7E;
yu10078999 2:807d696cf266 62 mac[5] = 0x1C;
Jeffdhyan 3:97c3e915a108 63 };