Usage example, Xively with wolfSSL

Dependencies:   EthernetInterface HTTPClient SDFileSystem mbed-rtos mbed wolfSSL

Fork of SimpleXively by wolf SSL

Files at this revision

API Documentation at this revision

Comitter:
wolfSSL
Date:
Tue Jul 21 23:16:48 2015 +0000
Parent:
1:60e6225ef3e5
Commit message:
Initial public version

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
wolfSSL.lib Show annotated file Show diff for this revision Revisions of this file
xively.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 60e6225ef3e5 -r 74161080023f HTTPClient.lib
--- a/HTTPClient.lib	Sat Feb 07 19:29:59 2015 +0000
+++ b/HTTPClient.lib	Tue Jul 21 23:16:48 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/wolfSSL/code/HTTPClient/#a9ecee69c6b5
+http://mbed.org/users/wolfSSL/code/HTTPClient/#77082c88748a
diff -r 60e6225ef3e5 -r 74161080023f SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Tue Jul 21 23:16:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
diff -r 60e6225ef3e5 -r 74161080023f main.cpp
--- a/main.cpp	Sat Feb 07 19:29:59 2015 +0000
+++ b/main.cpp	Tue Jul 21 23:16:48 2015 +0000
@@ -23,7 +23,8 @@
 #include "EthernetInterface.h"
 #include "HTTPClient.h"
 
-#define KEYS "https://SERVER_IP/574d76fcb/keys.txt"
+#include <SDFileSystem.h>
+SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd");
 
 #define BUFFSIZE (50+1)
 
@@ -34,24 +35,21 @@
 
 void thread_main(void const *av)
 {
-    int ret ; 
     int i ;
-    char recvBuff[BUFFSIZE*6] ;
-    char dummy1[BUFFSIZE], dummy2[BUFFSIZE], dummy3[BUFFSIZE], dummy4[BUFFSIZE] ;
-    char feed_id[BUFFSIZE] ;
-    char api_key[BUFFSIZE] ;
     char ch_name[BUFFSIZE] ;
-  
-    memset(recvBuff, '\0', sizeof(recvBuff)) ;
-    ret = http.get(KEYS, recvBuff, sizeof(recvBuff));
-    if (ret) {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+    FILE *fp ;
+    char id[BUFFSIZE], key[BUFFSIZE] ;
+    
+    fp = fopen("/sd/XivelyKey.txt", "r");
+    if (fp == NULL) {
+        printf("Cannot open \"XivelyKey.txt\"\n") ;
         return ;
     }
-
-    sscanf(recvBuff, "%50s\n%50s\n%50s\n%50s\n%50s\n%50s", feed_id, api_key,
-         dummy1, dummy2, dummy3, dummy4) ;
-    printf("ID=%s\nKey=%s\n",feed_id, api_key) ;
+    fgets(id, sizeof(id), fp) ; 
+    if((id[strlen(id)-2] == '\n')||(id[strlen(id)-2] == '\r'))id[strlen(id)-2] = '\0' ;
+    fgets(key, sizeof(key), fp) ; 
+    if((key[strlen(key)-2] == '\n')||(key[strlen(key)-2] == '\r'))key[strlen(key)-2] = '\0' ;
+    printf("ID=%s\nKey=%s\n",id, key) ;
     
     printf("Channel Name:") ;
     for(i=0; i<BUFFSIZE; i++) {
@@ -62,7 +60,7 @@
         } else putchar(ch_name[i]) ;
     }
     
-    xively_main(feed_id, api_key, ch_name) ;
+    xively_main(id, key, ch_name) ;
     
     while (true) {
         Thread::wait(1000);
diff -r 60e6225ef3e5 -r 74161080023f mbed-rtos.lib
--- a/mbed-rtos.lib	Sat Feb 07 19:29:59 2015 +0000
+++ b/mbed-rtos.lib	Tue Jul 21 23:16:48 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#f1ef95efa5ad
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5aed8bae1001
diff -r 60e6225ef3e5 -r 74161080023f wolfSSL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wolfSSL.lib	Tue Jul 21 23:16:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/wolfSSL/code/wolfSSL/#28278596c2a2
diff -r 60e6225ef3e5 -r 74161080023f xively.cpp
--- a/xively.cpp	Sat Feb 07 19:29:59 2015 +0000
+++ b/xively.cpp	Tue Jul 21 23:16:48 2015 +0000
@@ -48,7 +48,8 @@
 
     sprintf(header, "X-ApiKey: %s\r\n", api_key) ;
     http.setHeader(header) ;
- 
+    http.dumpReqHeader(true) ;
+    http.dumpResHeader(true) ;
     for(i=0; ; i++) {
         printf("<<<< %d >>>>\n", i) ;
         sprintf(uri, "%s/%s.json", XI_API, feed_id) ;
@@ -60,7 +61,7 @@
 
         ret = http.put(uri, outText, &inText) ;
         if (!ret) {
-            printf("== PUT - read %d ==\n", strlen(buff));
+            printf("\n== HTTP PUT: OK\n\n");
             if(strlen(buff))
                 printf("Result: %s\n", buff);
         } else {