This is a demo that upload temperature info. to dweet.io
Dependencies: BLE_API DHT HTTPClient SDFileSystem WIZnet_Library mbed nRF51822
Diff: main.cpp
- Revision:
- 2:8b304d2b4ca5
- Parent:
- 1:0f6a216263aa
- Child:
- 3:cfc6ff08a668
diff -r 0f6a216263aa -r 8b304d2b4ca5 main.cpp --- a/main.cpp Tue Jun 30 05:41:58 2015 +0000 +++ b/main.cpp Tue Jun 30 07:28:24 2015 +0000 @@ -2,9 +2,9 @@ #include "SDFileSystem.h" #include "BLE.h" #include "WIZnetInterface.h" - +#include "HTTPClient.h" -#define USE_DHCP 1 +#define USE_DHCP 0 #define LOOPBACKPORT 5000 int W5500_Test(void); @@ -29,34 +29,63 @@ wait(1); printf("helloworld\r\n"); - if(W5500_Test() == 0) { + if(W5500_Test() == 0) { // Internet is ok printf("W5500 tested OK \r\n"); - TCPSocketServer server; + char str[512]; + char get_msg[128]= ""; + + /* + http://dweet.io/follow/nameYouWant + */ + char nameYouWant[] = "nameYouWant"; + while(1) + { +// sprintf(get_msg,"http://dweet.io/dweet/for/%s?a0=%d",nameYouWant,(int)(1000)); + + sprintf(get_msg,"http://seeedmsvps.cloudapp.net:10080/plantbox/upload_iot/"); + HTTPClient http; - server.bind(LOOPBACKPORT); - server.listen(); - while(1) { - printf("\nWait for new connection...\r\n"); - TCPSocketConnection client; - server.accept(client); - client.set_blocking(false,0); // Timeout = 0. - printf("Connection from: %s\r\n",client.get_address()); - while (client.is_connected() == true) { - int n = client.receive(buffer,sizeof(buffer)); - if (n > 0) { - client.send_all(buffer,n); - } else { - } - if (client.is_fin_received()) { - client.close(); - } else { - } + pc.printf("Send post message to dweet.io\r\n"); + pc.printf("msg : %s\r\n",get_msg); + ret = http.get(get_msg, str, sizeof(str)); + if(!ret) + { + pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); + pc.printf("Result: %s\r\n", str); + } + else + { + pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + wait(10); + } + + + // TCPSocketServer server; + // server.bind(LOOPBACKPORT); + // server.listen(); + // while(1) { + // printf("\nWait for new connection...\r\n"); + // TCPSocketConnection client; + // server.accept(client); + // client.set_blocking(false,0); // Timeout = 0. + // printf("Connection from: %s\r\n",client.get_address()); + // while (client.is_connected() == true) { + // int n = client.receive(buffer,sizeof(buffer)); + // if (n > 0) { + // client.send_all(buffer,n); + // } else { + // } + // if (client.is_fin_received()) { + // client.close(); + // } else { + // } - } - printf("Disconnected.\r\n"); + // } + // printf("Disconnected.\r\n"); - } + // } } while(1) {