The Ethernet-Board

Dependencies:   EthernetInterface HTTPClient MODSERIAL mbed-dev mbed-rtos wolfSSL

Fork of sose2016_tr_oauth_pop by niko gillen

Committer:
coolnik
Date:
Sat Jun 18 11:34:56 2016 +0000
Revision:
1:5f0df6a77d62
Parent:
0:64d0faaa4e6e
Child:
2:1ffd9e2ce7df
changes

Who changed what in which revision?

UserRevisionLine numberNew 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 1:5f0df6a77d62 5 DigitalOut R(PTB22); // PTB22 = Red pin
coolnik 1:5f0df6a77d62 6 DigitalOut G(PTE26); // PTE26 = Green pin
coolnik 1:5f0df6a77d62 7 DigitalOut B(PTB21); // PTB21 = Blue pin
coolnik 1:5f0df6a77d62 8
coolnik 1:5f0df6a77d62 9 Serial serial(USBTX, USBRX); // tx, rx
coolnik 0:64d0faaa4e6e 10 EthernetInterface eth;
coolnik 0:64d0faaa4e6e 11 HTTPClient http;
coolnik 1:5f0df6a77d62 12 char str[8192];
coolnik 0:64d0faaa4e6e 13
coolnik 0:64d0faaa4e6e 14 int main() {
coolnik 0:64d0faaa4e6e 15 setbuf(stdout, NULL);
coolnik 0:64d0faaa4e6e 16 eth.init(); //Use DHCP
coolnik 0:64d0faaa4e6e 17 eth.connect();
coolnik 1:5f0df6a77d62 18
coolnik 1:5f0df6a77d62 19 while(1){
coolnik 1:5f0df6a77d62 20 // Wait for Token on Serial and read to str
coolnik 1:5f0df6a77d62 21 while(1){
coolnik 1:5f0df6a77d62 22 if(serial.readable()){
coolnik 1:5f0df6a77d62 23 serial.scanf("%s",&str);
coolnik 1:5f0df6a77d62 24 break;
coolnik 1:5f0df6a77d62 25 }
coolnik 1:5f0df6a77d62 26 }
coolnik 1:5f0df6a77d62 27 printf(str);
coolnik 1:5f0df6a77d62 28
coolnik 1:5f0df6a77d62 29 // Send token to Server
coolnik 1:5f0df6a77d62 30 http.dumpResHeader(true);
coolnik 1:5f0df6a77d62 31 // GET date, more examples on https://developer.mbed.org/users/donatien/code/HTTPClient_HelloWorld/file/270e2d0bb85a/main.cpp
coolnik 1:5f0df6a77d62 32 printf("\nTrying to fetch page...\n");
coolnik 1:5f0df6a77d62 33 //int ret = http.get("https://kongsugar.de/text.txt", str, 128);
coolnik 1:5f0df6a77d62 34 int ret = http.get("https://46.101.218.232/text.txt", str, 64000);
coolnik 0:64d0faaa4e6e 35
coolnik 1:5f0df6a77d62 36 if (!ret)
coolnik 1:5f0df6a77d62 37 {
coolnik 1:5f0df6a77d62 38 printf("Page fetched successfully - read %d characters\n", strlen(str));
coolnik 1:5f0df6a77d62 39 printf("Result: %s\n", str);
coolnik 1:5f0df6a77d62 40 // Unlock
coolnik 1:5f0df6a77d62 41 R=!R;
coolnik 1:5f0df6a77d62 42 wait(1);
coolnik 1:5f0df6a77d62 43 R=!R;
coolnik 1:5f0df6a77d62 44 }
coolnik 1:5f0df6a77d62 45 else
coolnik 1:5f0df6a77d62 46 {
coolnik 1:5f0df6a77d62 47 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
coolnik 1:5f0df6a77d62 48 }
coolnik 0:64d0faaa4e6e 49 }
coolnik 1:5f0df6a77d62 50
coolnik 0:64d0faaa4e6e 51 eth.disconnect();
coolnik 0:64d0faaa4e6e 52 }