This is an example for sending queries to IFTTT using WIZwiki-W7500.
Dependencies: IFTTT WIZnetInterface mbed
main.cpp@0:0d7ef0c464ff, 2015-07-22 (annotated)
- Committer:
- jehoon
- Date:
- Wed Jul 22 12:03:28 2015 +0000
- Revision:
- 0:0d7ef0c464ff
This is an example for sending queries to IFTTT(If This Then That) using WIZwiki-W7500 platform.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jehoon | 0:0d7ef0c464ff | 1 | #include "mbed.h" |
jehoon | 0:0d7ef0c464ff | 2 | #include "EthernetInterface.h" |
jehoon | 0:0d7ef0c464ff | 3 | #include "TCPSocketConnection.h" |
jehoon | 0:0d7ef0c464ff | 4 | #include "ifttt.h" |
jehoon | 0:0d7ef0c464ff | 5 | |
jehoon | 0:0d7ef0c464ff | 6 | EthernetInterface eth; |
jehoon | 0:0d7ef0c464ff | 7 | Serial pc(USBTX, USBRX); // tx, rx |
jehoon | 0:0d7ef0c464ff | 8 | |
jehoon | 0:0d7ef0c464ff | 9 | int main() |
jehoon | 0:0d7ef0c464ff | 10 | { |
jehoon | 0:0d7ef0c464ff | 11 | int phy_link; |
jehoon | 0:0d7ef0c464ff | 12 | pc.baud(115200); |
jehoon | 0:0d7ef0c464ff | 13 | |
jehoon | 0:0d7ef0c464ff | 14 | printf("Wait a second...\r\n"); |
jehoon | 0:0d7ef0c464ff | 15 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; |
jehoon | 0:0d7ef0c464ff | 16 | eth.init(mac_addr); //Use DHCP |
jehoon | 0:0d7ef0c464ff | 17 | eth.connect(); |
jehoon | 0:0d7ef0c464ff | 18 | |
jehoon | 0:0d7ef0c464ff | 19 | do{ |
jehoon | 0:0d7ef0c464ff | 20 | phy_link = eth.ethernet_link(); |
jehoon | 0:0d7ef0c464ff | 21 | printf("..."); |
jehoon | 0:0d7ef0c464ff | 22 | wait(2); |
jehoon | 0:0d7ef0c464ff | 23 | }while(!phy_link); |
jehoon | 0:0d7ef0c464ff | 24 | printf("\r\nIP Address is %s \r\n", eth.getIPAddress()); |
jehoon | 0:0d7ef0c464ff | 25 | TCPSocketConnection sock; |
jehoon | 0:0d7ef0c464ff | 26 | |
jehoon | 0:0d7ef0c464ff | 27 | // Initialize ifttt object, add up to 3 optional values, trigger event. |
jehoon | 0:0d7ef0c464ff | 28 | IFTTT ifttt("YourEventName","ChangeToYourSecretKey", &sock); // EventName, Secret Key, socket to use |
jehoon | 0:0d7ef0c464ff | 29 | ifttt.addIngredients("this is awesome","test-ing","data!!!"); // 3 optional Values to send along with trigger. |
jehoon | 0:0d7ef0c464ff | 30 | ifttt.trigger(); |
jehoon | 0:0d7ef0c464ff | 31 | |
jehoon | 0:0d7ef0c464ff | 32 | // Send data using GET |
jehoon | 0:0d7ef0c464ff | 33 | ifttt.addIngredients("Sending","GET","data"); |
jehoon | 0:0d7ef0c464ff | 34 | ifttt.trigger(IFTTT_GET); |
jehoon | 0:0d7ef0c464ff | 35 | |
jehoon | 0:0d7ef0c464ff | 36 | // Send Data using POST |
jehoon | 0:0d7ef0c464ff | 37 | ifttt.addIngredients("Sending","POST","things"); |
jehoon | 0:0d7ef0c464ff | 38 | ifttt.trigger(IFTTT_POST); |
jehoon | 0:0d7ef0c464ff | 39 | |
jehoon | 0:0d7ef0c464ff | 40 | sock.close(); |
jehoon | 0:0d7ef0c464ff | 41 | eth.disconnect(); |
jehoon | 0:0d7ef0c464ff | 42 | |
jehoon | 0:0d7ef0c464ff | 43 | while(1) { |
jehoon | 0:0d7ef0c464ff | 44 | } |
jehoon | 0:0d7ef0c464ff | 45 | } |