A simple sample program to trigger Maker Channel of IFTTT from mbed LPC1114FN28.
Dependencies: W5500Interface mbed
Fork of AxedaGo-mbedNXP_WIZ550io by
main.cpp@8:fdf9f583358f, 2015-06-29 (annotated)
- Committer:
- ytsuboi
- Date:
- Mon Jun 29 03:36:46 2015 +0000
- Revision:
- 8:fdf9f583358f
- Parent:
- 7:880cc185d511
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AxedaCorp | 0:ab4e84579da0 | 1 | #include "mbed.h" |
AxedaCorp | 0:ab4e84579da0 | 2 | #include "EthernetInterface.h" |
embeddist | 7:880cc185d511 | 3 | |
embeddist | 7:880cc185d511 | 4 | #if defined(TARGET_LPC1114) |
embeddist | 7:880cc185d511 | 5 | SPI spi(dp2, dp1, dp6); // mosi, miso, sclk |
embeddist | 7:880cc185d511 | 6 | EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset |
embeddist | 7:880cc185d511 | 7 | AnalogIn pot1(dp13); |
embeddist | 7:880cc185d511 | 8 | #else |
embeddist | 7:880cc185d511 | 9 | EthernetInterface eth; |
embeddist | 7:880cc185d511 | 10 | AnalogIn pot1(p19); |
embeddist | 7:880cc185d511 | 11 | AnalogIn pot2(p20); |
embeddist | 7:880cc185d511 | 12 | #endif |
embeddist | 7:880cc185d511 | 13 | |
embeddist | 7:880cc185d511 | 14 | #if defined(TARGET_LPC1768) |
AxedaCorp | 0:ab4e84579da0 | 15 | DigitalOut led1(LED1); |
AxedaCorp | 0:ab4e84579da0 | 16 | DigitalOut led2(LED2); |
AxedaCorp | 0:ab4e84579da0 | 17 | DigitalOut led3(LED3); |
embeddist | 7:880cc185d511 | 18 | DigitalOut led4(LED4); |
embeddist | 7:880cc185d511 | 19 | #endif |
embeddist | 7:880cc185d511 | 20 | |
embeddist | 7:880cc185d511 | 21 | TCPSocketConnection sock; |
AxedaCorp | 0:ab4e84579da0 | 22 | |
AxedaCorp | 0:ab4e84579da0 | 23 | int main() |
AxedaCorp | 0:ab4e84579da0 | 24 | { |
ytsuboi | 8:fdf9f583358f | 25 | // YOU NEED TO TYPE THESE TWO VALUES |
ytsuboi | 8:fdf9f583358f | 26 | char *EVENT = "PUT YOUR EVENT NAME HERE"; |
ytsuboi | 8:fdf9f583358f | 27 | char *KEY = "PUT YOUT SECRET KEY HERE"; |
ytsuboi | 8:fdf9f583358f | 28 | // |
AxedaCorp | 0:ab4e84579da0 | 29 | |
AxedaCorp | 0:ab4e84579da0 | 30 | char* ip; |
AxedaCorp | 0:ab4e84579da0 | 31 | |
AxedaCorp | 3:359e019da3b9 | 32 | int http_cmd_sz=800; |
AxedaCorp | 3:359e019da3b9 | 33 | char http_cmd[http_cmd_sz]; |
AxedaCorp | 3:359e019da3b9 | 34 | int buffer_sz=300; |
AxedaCorp | 3:359e019da3b9 | 35 | char buffer[buffer_sz]; |
AxedaCorp | 0:ab4e84579da0 | 36 | int returnCode = 0; |
AxedaCorp | 0:ab4e84579da0 | 37 | |
embeddist | 7:880cc185d511 | 38 | #if defined(TARGET_LPC1768) |
AxedaCorp | 0:ab4e84579da0 | 39 | led1 = 1; |
AxedaCorp | 0:ab4e84579da0 | 40 | led2 = 1; |
AxedaCorp | 0:ab4e84579da0 | 41 | led3 = 1; |
AxedaCorp | 0:ab4e84579da0 | 42 | led4 = 1; |
embeddist | 7:880cc185d511 | 43 | #endif |
AxedaCorp | 0:ab4e84579da0 | 44 | |
AxedaCorp | 0:ab4e84579da0 | 45 | printf("initializing Ethernet\r\n"); |
AxedaCorp | 0:ab4e84579da0 | 46 | returnCode = eth.init(); //Use DHCP |
AxedaCorp | 0:ab4e84579da0 | 47 | |
AxedaCorp | 0:ab4e84579da0 | 48 | if ( returnCode == 0 ) |
AxedaCorp | 0:ab4e84579da0 | 49 | { |
AxedaCorp | 0:ab4e84579da0 | 50 | printf(" - Ethernet ready\r\n"); |
embeddist | 7:880cc185d511 | 51 | #if defined(TARGET_LPC1768) |
AxedaCorp | 0:ab4e84579da0 | 52 | led1 = returnCode; |
embeddist | 7:880cc185d511 | 53 | #endif |
AxedaCorp | 0:ab4e84579da0 | 54 | } |
AxedaCorp | 0:ab4e84579da0 | 55 | else |
AxedaCorp | 0:ab4e84579da0 | 56 | { |
AxedaCorp | 0:ab4e84579da0 | 57 | printf(" - Could not initialize Ethernet - ending\r\n"); |
AxedaCorp | 0:ab4e84579da0 | 58 | return 0; |
AxedaCorp | 0:ab4e84579da0 | 59 | } |
AxedaCorp | 0:ab4e84579da0 | 60 | |
AxedaCorp | 0:ab4e84579da0 | 61 | printf("Ethernet.connecting \r\n"); |
AxedaCorp | 0:ab4e84579da0 | 62 | returnCode = eth.connect(); |
AxedaCorp | 0:ab4e84579da0 | 63 | printf(" - connecting returned %d \r\n", returnCode); |
embeddist | 7:880cc185d511 | 64 | #if defined(TARGET_LPC1768) |
AxedaCorp | 0:ab4e84579da0 | 65 | led2 = returnCode != -1 ? 0: 1; |
embeddist | 7:880cc185d511 | 66 | #endif |
AxedaCorp | 0:ab4e84579da0 | 67 | printf("Trying to get IP address..\r\n"); |
AxedaCorp | 0:ab4e84579da0 | 68 | ip = eth.getIPAddress(); |
embeddist | 7:880cc185d511 | 69 | #if defined(TARGET_LPC1768) |
AxedaCorp | 0:ab4e84579da0 | 70 | led3 = strlen(ip)<4 ? 1: 0; |
embeddist | 7:880cc185d511 | 71 | #endif |
AxedaCorp | 0:ab4e84579da0 | 72 | printf(" - IP address:%s\r\n", ip); |
AxedaCorp | 0:ab4e84579da0 | 73 | |
ytsuboi | 8:fdf9f583358f | 74 | sock.connect("maker.ifttt.com", 80); |
ytsuboi | 8:fdf9f583358f | 75 | snprintf(http_cmd, http_cmd_sz, "GET /trigger/%s/with/key/%s HTTP/1.1\r\nHost: maker.ifttt.com\r\n\r\n", EVENT, KEY); |
AxedaCorp | 5:1b8ad120cf29 | 76 | sock.send_all(http_cmd, http_cmd_sz-1); |
AxedaCorp | 0:ab4e84579da0 | 77 | |
AxedaCorp | 5:1b8ad120cf29 | 78 | while ( (returnCode = sock.receive(buffer, buffer_sz-1)) > 0) |
AxedaCorp | 0:ab4e84579da0 | 79 | { |
AxedaCorp | 0:ab4e84579da0 | 80 | buffer[returnCode] = '\0'; |
AxedaCorp | 0:ab4e84579da0 | 81 | printf("Received %d chars from server:\n\r%s\n", returnCode, buffer); |
AxedaCorp | 0:ab4e84579da0 | 82 | } |
AxedaCorp | 0:ab4e84579da0 | 83 | sock.close(); |
AxedaCorp | 0:ab4e84579da0 | 84 | } |