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

Revision:
5:4d53cdfe94c4
Parent:
4:68c5a3f49a48
Child:
7:dceeeeca2741
--- a/main.cpp	Sat Feb 07 19:14:32 2015 +0000
+++ b/main.cpp	Wed Aug 05 22:58:16 2015 +0000
@@ -4,7 +4,9 @@
 
 EthernetInterface eth;
 HTTPClient http;
-char recvBuff[1024*20];
+DigitalOut led1(LED1);
+
+char recvBuff[1024*40];
 
 void getline(char *line, int size) {
     for(int i=0; i<size; i++) {
@@ -16,47 +18,78 @@
     }
 }
 
+unsigned long long atoll(char *instr)
+{
+  unsigned long long retval;
+  //int i;
+
+  retval = 0;
+  for (; *instr; instr++) {
+    retval = 10*retval + (*instr - '0');
+  }
+  return retval;
+}
+
+void baud(int baudrate) {
+    Serial s(USBTX, USBRX);
+    s.baud(baudrate);
+}
+
 void net_main(void const *av)
 {
     int ret ;
+    //char substr[10];
+    char *found;
+    char twitteTag[] = "data-time=";
+    char createDate[11] = {0};
+    unsigned long long dataTime = 0;
+    unsigned long long lastdataTime = 1438467674;
 
     eth.init(); //Use DHCP
-    printf("HTTP Client, Starting,...\n") ;
+    
+    printf("HTTPS Client, Starting,...\n\r") ;
     while(1) {
         if(eth.connect() == 0)break ;
         printf("Retry\n") ;
     }
-    
-    /*** HTTP ***/
-    printf("\nFetching HTTP\n");
-    ret = http.get("http://SERVER_IP/574d76fcb/keys.txt", recvBuff, sizeof(recvBuff));
-    if (!ret) {
-        printf("Result: %s\n", recvBuff);
-    } else {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+
+    while(1)
+    {
+        /*** HTTPS (SSL) ***/
+        printf("\nFetching HTTPS\n\r");
+        //ret = http.get("https://twitter.com/fsl_mcu.html", recvBuff, sizeof(recvBuff));
+        ret = http.get("https://twitter.com/hashtag/tweetforacandy?f=tweets&amp;src=hash", recvBuff, sizeof(recvBuff),HTTP_CLIENT_DEFAULT_TIMEOUT);
+        if (!ret) {
+            printf("Result: %s\n\r", recvBuff);
+              found = strstr(recvBuff, twitteTag);
+              snprintf(createDate, sizeof (createDate), found+11);
+              dataTime = atoll(createDate);
+              printf("The data-time: %s\r\n", createDate);
+              
+              if (lastdataTime < dataTime)
+              {
+                  //Give the candy here!!
+                  led1 = 0;
+                  lastdataTime = dataTime;
+                  wait(1);
+                  led1 = 1;
+              }
+        } else {
+            printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
+        }
+        wait(30);
     }
-    
-    /*** HTTPS (SSL) ***/
-    printf("\nFetching HTTPS\n");
-    ret = http.get("https://SERVER_IP/574d76fcb/keys.txt", 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()
 {
-
+    led1 = 1;
+    baud (115200);
+    
 #define STACK_SIZE 20000
-    Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);
-
+        Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);
     while (true) {
-        Thread::wait(1000);
+        Thread::wait(2000);
     }
 }