The Ethernet-Board

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

Fork of sose2016_tr_oauth_pop by niko gillen

main.cpp

Committer:
coolnik
Date:
2016-06-18
Revision:
1:5f0df6a77d62
Parent:
0:64d0faaa4e6e
Child:
2:1ffd9e2ce7df

File content as of revision 1:5f0df6a77d62:

#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"

DigitalOut R(PTB22);                  // PTB22 = Red   pin
DigitalOut G(PTE26);                  // PTE26 = Green pin
DigitalOut B(PTB21);                  // PTB21 = Blue  pin

Serial serial(USBTX, USBRX); // tx, rx
EthernetInterface eth;
HTTPClient http;
char str[8192];

int main() {
    setbuf(stdout, NULL);
    eth.init(); //Use DHCP
    eth.connect();

    while(1){
        // Wait for Token on Serial and read to str
        while(1){
               if(serial.readable()){
                    serial.scanf("%s",&str);
                    break;
                }
        }
        printf(str);
        
        // Send token to Server
        http.dumpResHeader(true);
        // GET date, more examples on https://developer.mbed.org/users/donatien/code/HTTPClient_HelloWorld/file/270e2d0bb85a/main.cpp
        printf("\nTrying to fetch page...\n");
        //int ret = http.get("https://kongsugar.de/text.txt", str, 128);
        int ret = http.get("https://46.101.218.232/text.txt", str, 64000);
    
        if (!ret)
        {
          printf("Page fetched successfully - read %d characters\n", strlen(str));
          printf("Result: %s\n", str);
          // Unlock
          R=!R;
          wait(1);
          R=!R;
        }
        else
        {
          printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
        }
    }
    
    eth.disconnect();  
}