This example codes uses the wolfssl library to get hastags from Twitter by using the FRDM-K64F board from Freescale

Dependencies:   EthernetInterface-FRDM HTTPClient mbed-rtos mbed wolfSSL WDT_K64F

Fork of SimpleHTTPSClient by wolf SSL

main.cpp

Committer:
wolfSSL
Date:
2014-12-08
Revision:
2:071a8275fa40
Parent:
1:54bce95d1d97
Child:
3:41412e91afb0

File content as of revision 2:071a8275fa40:

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

#define SERVER_URL      "http://192.168.49.57/574d76fcb/keys.txt"
#define SERVER_URL_SSL "https://192.168.49.57/574d76fcb/keys.txt"

EthernetInterface eth;
HTTPClient http;
char recvBuff[1024*20];

void net_main(void const *av)
{
    int ret ;

    eth.init(); //Use DHCP
    printf("HTTP Client, Starting,...\n") ;
    while(1) {
        if(eth.connect() == 0)break ;
        printf("Retry\n") ;
    }
    
    printf("HTTP Client, IP Address is %s\n", eth.getIPAddress());
    
    /*** HTTP ***/
    printf("\nFetching... %s\n", SERVER_URL);
    ret = http.get(SERVER_URL, recvBuff, sizeof(recvBuff));
    if (!ret) {
        printf("Result: %s\n", recvBuff);
    } else {
        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
    }
    
    wait(5.0) ;
    
    /*** HTTPS (SSL) ***/
    printf("\nFetching... %s\n", SERVER_URL_SSL);
    ret = http.get(SERVER_URL_SSL, recvBuff, sizeof(recvBuff));
    if (!ret) {
        printf("Result: %s\n", recvBuff);
    } else {
        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
    }
    
    eth.disconnect();
    while(1) {
    }
}

main()
{

#define STACK_SIZE 20000
    Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);

    while (true) {
        Thread::wait(1000);
    }
}