The Ethernet-Board
Dependencies: EthernetInterface HTTPClient MODSERIAL mbed-dev mbed-rtos wolfSSL
Fork of sose2016_tr_oauth_pop by
main.cpp@0:64d0faaa4e6e, 2016-06-16 (annotated)
- Committer:
- coolnik
- Date:
- Thu Jun 16 18:46:16 2016 +0000
- Revision:
- 0:64d0faaa4e6e
- Child:
- 1:5f0df6a77d62
inital
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
coolnik | 0:64d0faaa4e6e | 1 | #include "mbed.h" |
coolnik | 0:64d0faaa4e6e | 2 | #include "EthernetInterface.h" |
coolnik | 0:64d0faaa4e6e | 3 | #include "HTTPClient.h" |
coolnik | 0:64d0faaa4e6e | 4 | |
coolnik | 0:64d0faaa4e6e | 5 | DigitalOut myled(PTB21); |
coolnik | 0:64d0faaa4e6e | 6 | EthernetInterface eth; |
coolnik | 0:64d0faaa4e6e | 7 | HTTPClient http; |
coolnik | 0:64d0faaa4e6e | 8 | char str[64000]; |
coolnik | 0:64d0faaa4e6e | 9 | |
coolnik | 0:64d0faaa4e6e | 10 | int main() { |
coolnik | 0:64d0faaa4e6e | 11 | setbuf(stdout, NULL); |
coolnik | 0:64d0faaa4e6e | 12 | eth.init(); //Use DHCP |
coolnik | 0:64d0faaa4e6e | 13 | eth.connect(); |
coolnik | 0:64d0faaa4e6e | 14 | |
coolnik | 0:64d0faaa4e6e | 15 | printf("\nTrying to fetch page...\n"); |
coolnik | 0:64d0faaa4e6e | 16 | //int ret = http.get("https://kongsugar.de/text.txt", str, 128); |
coolnik | 0:64d0faaa4e6e | 17 | int ret = http.get("https://kongsugar.de/text.txt", str, 64000); |
coolnik | 0:64d0faaa4e6e | 18 | |
coolnik | 0:64d0faaa4e6e | 19 | if (!ret) |
coolnik | 0:64d0faaa4e6e | 20 | { |
coolnik | 0:64d0faaa4e6e | 21 | printf("Page fetched successfully - read %d characters\n", strlen(str)); |
coolnik | 0:64d0faaa4e6e | 22 | printf("Result: %s\n", str); |
coolnik | 0:64d0faaa4e6e | 23 | myled=!myled; |
coolnik | 0:64d0faaa4e6e | 24 | myled=!myled; |
coolnik | 0:64d0faaa4e6e | 25 | } |
coolnik | 0:64d0faaa4e6e | 26 | else |
coolnik | 0:64d0faaa4e6e | 27 | { |
coolnik | 0:64d0faaa4e6e | 28 | printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
coolnik | 0:64d0faaa4e6e | 29 | } |
coolnik | 0:64d0faaa4e6e | 30 | while(1) { |
coolnik | 0:64d0faaa4e6e | 31 | |
coolnik | 0:64d0faaa4e6e | 32 | } |
coolnik | 0:64d0faaa4e6e | 33 | eth.disconnect(); |
coolnik | 0:64d0faaa4e6e | 34 | } |