add messages print out.
Dependencies: EthernetInterface IFTTT mbed-rtos mbed
Fork of IFTTT_Ethernet_Example by
main.cpp@3:34f1df7fd14c, 2016-09-11 (annotated)
- Committer:
- liutaitsung
- Date:
- Sun Sep 11 04:57:14 2016 +0000
- Revision:
- 3:34f1df7fd14c
- Parent:
- 2:22857c849884
add messages print out.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
liutaitsung | 3:34f1df7fd14c | 1 | // |
liutaitsung | 3:34f1df7fd14c | 2 | // |
liutaitsung | 3:34f1df7fd14c | 3 | // |
liutaitsung | 3:34f1df7fd14c | 4 | |
mbedAustin | 0:0f0676c43e4b | 5 | #include "mbed.h" |
mbedAustin | 0:0f0676c43e4b | 6 | #include "EthernetInterface.h" |
mbedAustin | 1:3010b44f07ff | 7 | #include "TCPSocketConnection.h" |
mbedAustin | 1:3010b44f07ff | 8 | #include "ifttt.h" |
mbedAustin | 1:3010b44f07ff | 9 | |
liutaitsung | 3:34f1df7fd14c | 10 | // |
liutaitsung | 3:34f1df7fd14c | 11 | // |
liutaitsung | 3:34f1df7fd14c | 12 | // |
liutaitsung | 3:34f1df7fd14c | 13 | |
mbedAustin | 0:0f0676c43e4b | 14 | EthernetInterface eth; |
liutaitsung | 3:34f1df7fd14c | 15 | |
mbedAustin | 1:3010b44f07ff | 16 | RawSerial pc(USBTX, USBRX); // tx, rx |
mbedAustin | 0:0f0676c43e4b | 17 | |
mbedAustin | 1:3010b44f07ff | 18 | int main() |
mbedAustin | 0:0f0676c43e4b | 19 | { |
mbedAustin | 1:3010b44f07ff | 20 | pc.baud(9600); |
liutaitsung | 3:34f1df7fd14c | 21 | |
liutaitsung | 3:34f1df7fd14c | 22 | pc.printf("\n"); |
liutaitsung | 3:34f1df7fd14c | 23 | pc.printf("\n"); |
liutaitsung | 3:34f1df7fd14c | 24 | pc.printf("--------------------------------\n"); |
liutaitsung | 3:34f1df7fd14c | 25 | pc.printf("Program starts ...\n"); |
liutaitsung | 3:34f1df7fd14c | 26 | |
liutaitsung | 3:34f1df7fd14c | 27 | // eth.init(); //Use DHCP |
liutaitsung | 3:34f1df7fd14c | 28 | int init_rtn = eth.init(); //Use DHCP |
liutaitsung | 3:34f1df7fd14c | 29 | |
liutaitsung | 3:34f1df7fd14c | 30 | pc.printf("init() return : %d\n", init_rtn); |
liutaitsung | 3:34f1df7fd14c | 31 | |
liutaitsung | 3:34f1df7fd14c | 32 | pc.printf("\n"); |
liutaitsung | 3:34f1df7fd14c | 33 | pc.printf(" wait for ethernet connect()......\n"); |
liutaitsung | 3:34f1df7fd14c | 34 | pc.printf("\n"); |
liutaitsung | 3:34f1df7fd14c | 35 | |
liutaitsung | 3:34f1df7fd14c | 36 | |
liutaitsung | 3:34f1df7fd14c | 37 | // eth.connect(); |
liutaitsung | 3:34f1df7fd14c | 38 | int connect_rtn = eth.connect(); |
liutaitsung | 3:34f1df7fd14c | 39 | pc.printf("connect() return : %d\n", connect_rtn); |
liutaitsung | 3:34f1df7fd14c | 40 | |
mbedAustin | 0:0f0676c43e4b | 41 | printf("IP Address is %s \n\r", eth.getIPAddress()); |
liutaitsung | 3:34f1df7fd14c | 42 | |
liutaitsung | 3:34f1df7fd14c | 43 | pc.printf("IP Address is %s\n", eth.getMACAddress()); |
liutaitsung | 3:34f1df7fd14c | 44 | pc.printf("\n"); |
liutaitsung | 3:34f1df7fd14c | 45 | |
liutaitsung | 3:34f1df7fd14c | 46 | |
liutaitsung | 3:34f1df7fd14c | 47 | |
liutaitsung | 3:34f1df7fd14c | 48 | |
liutaitsung | 3:34f1df7fd14c | 49 | pc.printf("wait for socket server, 15 second ....\n"); |
liutaitsung | 3:34f1df7fd14c | 50 | pc.printf("\n"); |
liutaitsung | 3:34f1df7fd14c | 51 | |
liutaitsung | 3:34f1df7fd14c | 52 | |
mbedAustin | 1:3010b44f07ff | 53 | TCPSocketConnection socket; |
mbedAustin | 1:3010b44f07ff | 54 | |
mbedAustin | 1:3010b44f07ff | 55 | // Initialize ifttt object, add up to 3 optional values, trigger event. |
Jeffdhyan | 2:22857c849884 | 56 | IFTTT ifttt("hellowordmbed","ExqSjQiwzZINRMFTOgo--", &socket); // EventName, Secret Key, socket to use |
mbedAustin | 1:3010b44f07ff | 57 | ifttt.addIngredients("this is awesome","test-ing","data!!!"); // 3 optional Values to send along with trigger. |
mbedAustin | 1:3010b44f07ff | 58 | ifttt.trigger(); |
mbedAustin | 1:3010b44f07ff | 59 | |
mbedAustin | 1:3010b44f07ff | 60 | // Send data using GET |
mbedAustin | 1:3010b44f07ff | 61 | ifttt.addIngredients("Sending","GET","data"); |
mbedAustin | 1:3010b44f07ff | 62 | ifttt.trigger(IFTTT_GET); |
mbedAustin | 1:3010b44f07ff | 63 | |
mbedAustin | 1:3010b44f07ff | 64 | // Send Data using POST |
mbedAustin | 1:3010b44f07ff | 65 | ifttt.addIngredients("Sending","POST","things"); |
mbedAustin | 1:3010b44f07ff | 66 | ifttt.trigger(IFTTT_POST); |
mbedAustin | 1:3010b44f07ff | 67 | |
mbedAustin | 1:3010b44f07ff | 68 | eth.disconnect(); |
mbedAustin | 0:0f0676c43e4b | 69 | while(1) { |
mbedAustin | 0:0f0676c43e4b | 70 | } |
mbedAustin | 0:0f0676c43e4b | 71 | } |
liutaitsung | 3:34f1df7fd14c | 72 | |
liutaitsung | 3:34f1df7fd14c | 73 | // override the default weak function to provide a specific mac address |
liutaitsung | 3:34f1df7fd14c | 74 | extern "C" void mbed_mac_address(char *mac) |
liutaitsung | 3:34f1df7fd14c | 75 | { |
liutaitsung | 3:34f1df7fd14c | 76 | mac[0] = 0x00; |
liutaitsung | 3:34f1df7fd14c | 77 | mac[1] = 0x50; |
liutaitsung | 3:34f1df7fd14c | 78 | mac[2] = 0x56; |
liutaitsung | 3:34f1df7fd14c | 79 | mac[3] = 0xC0; |
liutaitsung | 3:34f1df7fd14c | 80 | mac[4] = 0x00; |
liutaitsung | 3:34f1df7fd14c | 81 | mac[5] = 0xAB; |
liutaitsung | 3:34f1df7fd14c | 82 | }; |