IFTTTに引数付きでPOST出来る様に改修

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of HTTPClient_IFTTT_Maker_post_HelloWorld by Ken Suzuki

Committer:
jksoft
Date:
Mon Jul 13 14:05:38 2015 +0000
Revision:
2:7101bf2516ef
Parent:
1:b713347c7f63
HTTPText?????JSON???POST??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kensuzuki 0:0bac9bcebae1 1 #include "mbed.h"
kensuzuki 0:0bac9bcebae1 2 #include "EthernetInterface.h"
kensuzuki 0:0bac9bcebae1 3 #include "HTTPClient.h"
kensuzuki 0:0bac9bcebae1 4
kensuzuki 0:0bac9bcebae1 5 EthernetInterface eth;
kensuzuki 0:0bac9bcebae1 6 HTTPClient http;
kensuzuki 0:0bac9bcebae1 7 char str[512];
kensuzuki 0:0bac9bcebae1 8 HTTPText inData(str, 512);
kensuzuki 0:0bac9bcebae1 9 Serial pc(USBTX, USBRX);
kensuzuki 0:0bac9bcebae1 10 int ret;
kensuzuki 0:0bac9bcebae1 11
kensuzuki 0:0bac9bcebae1 12 int main()
kensuzuki 0:0bac9bcebae1 13 {
kensuzuki 0:0bac9bcebae1 14
kensuzuki 0:0bac9bcebae1 15 eth.init();
kensuzuki 0:0bac9bcebae1 16 ret = eth.connect();
kensuzuki 0:0bac9bcebae1 17
kensuzuki 0:0bac9bcebae1 18 if (!ret) {
kensuzuki 0:0bac9bcebae1 19 pc.printf("ip: %s, %s, %s\r\n", eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
kensuzuki 0:0bac9bcebae1 20 } else {
kensuzuki 0:0bac9bcebae1 21 pc.printf("Ethernet connect failed. ret: %d\r\n", ret);
kensuzuki 0:0bac9bcebae1 22 return -1;
kensuzuki 0:0bac9bcebae1 23 }
kensuzuki 0:0bac9bcebae1 24
jksoft 2:7101bf2516ef 25 // HTTPMap map;
jksoft 2:7101bf2516ef 26 HTTPText outText(str, 512);
jksoft 2:7101bf2516ef 27 // map.put("value1", "Hello World.");
jksoft 2:7101bf2516ef 28 outText = "{ \"value1\" : \"Hello World.\"}";
jksoft 2:7101bf2516ef 29 ret = http.post("http://maker.ifttt.com/trigger/button_pressed/with/key/YOUR_SECRET_KEY", outText, &inData);
kensuzuki 0:0bac9bcebae1 30
kensuzuki 0:0bac9bcebae1 31 if (!ret) {
kensuzuki 0:0bac9bcebae1 32 pc.printf("HTTP request succeeded.\r\n");
kensuzuki 0:0bac9bcebae1 33 pc.printf("%s\r\n", str);
kensuzuki 0:0bac9bcebae1 34 } else {
kensuzuki 0:0bac9bcebae1 35 pc.printf("HTTP request failed. ret: %d, code: %d\r\n", ret, http.getHTTPResponseCode());
kensuzuki 0:0bac9bcebae1 36 }
kensuzuki 0:0bac9bcebae1 37
kensuzuki 0:0bac9bcebae1 38 eth.disconnect();
kensuzuki 0:0bac9bcebae1 39
kensuzuki 0:0bac9bcebae1 40 while(1) {
kensuzuki 0:0bac9bcebae1 41 }
kensuzuki 0:0bac9bcebae1 42 }