dennis liu / Mbed 2 deprecated IFTTT_Ethernet_Example_DL

Dependencies:   EthernetInterface IFTTT mbed-rtos mbed

Fork of IFTTT_Ethernet_Example by Jeff Chen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //
00002 //
00003 //
00004 
00005 #include "mbed.h"
00006 #include "EthernetInterface.h"
00007 #include "TCPSocketConnection.h"
00008 #include "ifttt.h"
00009 
00010 //
00011 //
00012 //
00013 
00014 EthernetInterface eth;
00015 
00016 RawSerial pc(USBTX, USBRX); // tx, rx
00017 
00018 int main()
00019 {
00020     pc.baud(9600);
00021     
00022     pc.printf("\n");
00023     pc.printf("\n");
00024     pc.printf("--------------------------------\n");
00025     pc.printf("Program starts ...\n");
00026     
00027 //    eth.init(); //Use DHCP
00028     int init_rtn = eth.init(); //Use DHCP
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 
00037 //    eth.connect();
00038     int connect_rtn = eth.connect();
00039     pc.printf("connect() return : %d\n", connect_rtn);
00040     
00041     printf("IP Address is %s \n\r", eth.getIPAddress());
00042 
00043     pc.printf("IP Address is %s\n", eth.getMACAddress());
00044     pc.printf("\n");
00045 
00046 
00047 
00048     
00049     pc.printf("wait for socket server, 15 second ....\n");
00050     pc.printf("\n");
00051     
00052 
00053     TCPSocketConnection socket;
00054 
00055     // Initialize ifttt object, add up to 3 optional values, trigger event.
00056     IFTTT ifttt("hellowordmbed","ExqSjQiwzZINRMFTOgo--", &socket); // EventName, Secret Key, socket to use
00057     ifttt.addIngredients("this is awesome","test-ing","data!!!");     // 3 optional Values to send along with trigger.
00058     ifttt.trigger();
00059 
00060     // Send data using GET
00061     ifttt.addIngredients("Sending","GET","data");
00062     ifttt.trigger(IFTTT_GET);
00063 
00064     // Send Data using POST
00065     ifttt.addIngredients("Sending","POST","things");
00066     ifttt.trigger(IFTTT_POST);
00067 
00068     eth.disconnect();
00069     while(1) {
00070     }
00071 }
00072 
00073 // override the default weak function to provide a specific mac address
00074 extern "C" void mbed_mac_address(char *mac)
00075 {
00076     mac[0] = 0x00;
00077     mac[1] = 0x50;
00078     mac[2] = 0x56;
00079     mac[3] = 0xC0;
00080     mac[4] = 0x00;
00081     mac[5] = 0xAB;
00082 };