Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HTTPClient mbed-rtos-initial-thread-larger-stack mbed wolfSSL
main.cpp@4:6b0e7a10a395, 2014-12-05 (annotated)
- Committer:
- takashikojo
- Date:
- Fri Dec 05 11:55:42 2014 +0000
- Revision:
- 4:6b0e7a10a395
- Parent:
- 1:2744673f6256
- Child:
- 5:6d00f26f7b59
Rollback main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takashikojo | 0:83075160de0e | 1 | #include "mbed.h" |
takashikojo | 0:83075160de0e | 2 | #include "EthernetInterface.h" |
takashikojo | 0:83075160de0e | 3 | #include "HTTPClient.h" |
takashikojo | 0:83075160de0e | 4 | |
takashikojo | 4:6b0e7a10a395 | 5 | #define SERVER_URL "https://192.168.1.12/index.html" |
takashikojo | 0:83075160de0e | 6 | |
takashikojo | 0:83075160de0e | 7 | EthernetInterface eth; |
takashikojo | 0:83075160de0e | 8 | HTTPClient http; |
takashikojo | 0:83075160de0e | 9 | char recvBuff[1024*20]; |
takashikojo | 0:83075160de0e | 10 | |
takashikojo | 0:83075160de0e | 11 | int main() |
takashikojo | 0:83075160de0e | 12 | { |
takashikojo | 4:6b0e7a10a395 | 13 | int ret ; |
takashikojo | 0:83075160de0e | 14 | |
takashikojo | 4:6b0e7a10a395 | 15 | printf("HTTP Client, Starting,...\n") ; |
takashikojo | 0:83075160de0e | 16 | |
takashikojo | 0:83075160de0e | 17 | eth.init(); //Use DHCP |
takashikojo | 0:83075160de0e | 18 | while(1) { |
takashikojo | 0:83075160de0e | 19 | printf("Trying\n") ; |
takashikojo | 4:6b0e7a10a395 | 20 | ret = eth.connect(); |
takashikojo | 4:6b0e7a10a395 | 21 | if(ret == 0)break ; |
takashikojo | 0:83075160de0e | 22 | } |
takashikojo | 0:83075160de0e | 23 | printf("HTTP Client, IP Address is %s\n", eth.getIPAddress()); |
takashikojo | 0:83075160de0e | 24 | |
takashikojo | 4:6b0e7a10a395 | 25 | while(1) { |
takashikojo | 4:6b0e7a10a395 | 26 | printf("\nTrying to fetch page... %s\n", SERVER_URL); |
takashikojo | 4:6b0e7a10a395 | 27 | memset(recvBuff, '\0', sizeof(recvBuff)) ; |
takashikojo | 4:6b0e7a10a395 | 28 | ret = http.get(SERVER_URL, recvBuff, sizeof(recvBuff),16); |
takashikojo | 0:83075160de0e | 29 | |
takashikojo | 4:6b0e7a10a395 | 30 | if (!ret) { |
takashikojo | 4:6b0e7a10a395 | 31 | printf("Result: %s\n", recvBuff); |
takashikojo | 4:6b0e7a10a395 | 32 | } else { |
takashikojo | 4:6b0e7a10a395 | 33 | printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
takashikojo | 4:6b0e7a10a395 | 34 | } |
takashikojo | 4:6b0e7a10a395 | 35 | wait(10.0) ; |
takashikojo | 0:83075160de0e | 36 | } |
takashikojo | 0:83075160de0e | 37 | |
takashikojo | 0:83075160de0e | 38 | eth.disconnect(); |
takashikojo | 0:83075160de0e | 39 | |
takashikojo | 0:83075160de0e | 40 | while(1) { |
takashikojo | 0:83075160de0e | 41 | } |
takashikojo | 4:6b0e7a10a395 | 42 | } |