Example node for Yodiwo's Plegma API

Dependencies:   EthernetInterface FXOS8700Q HTTPClient HTTPD MQTTS SDFileSystem YodiwoPlegma mbed-rpc mbed-rtos mbed wolfSSL

Files at this revision

API Documentation at this revision

Comitter:
mitsarionas
Date:
Tue Sep 01 12:01:50 2015 +0000
Parent:
0:00797f1ebe04
Child:
2:b7489c070d1f
Commit message:
getting tokens

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
pairing_backend.cpp Show annotated file Show diff for this revision Revisions of this file
pairing_backend.h Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.lib	Tue Sep 01 10:23:13 2015 +0000
+++ b/HTTPClient.lib	Tue Sep 01 12:01:50 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/wolfSSL/code/HTTPClient/#ac9de60bbf72
+http://developer.mbed.org/users/wolfSSL/code/HTTPClient/#77082c88748a
--- a/pairing_backend.cpp	Tue Sep 01 10:23:13 2015 +0000
+++ b/pairing_backend.cpp	Tue Sep 01 12:01:50 2015 +0000
@@ -2,11 +2,13 @@
 #include "HTTPClient.h"
 #include "mbed.h"
 #include "rtos.h"
+#include "yodiwo_helpers.h"
+#include "jsmn.h"
 
 HTTPClient http;
 char recvBuff[1024*20];
 int __get_tokens(pairing_context *ctx);
- 
+
 int pairing_context_init_with_defaults(pairing_context *ctx, onPaired_callback callback)
 {
     ctx->postUrl = "http://10.30.254.199:3334/pairing/";
@@ -47,8 +49,8 @@
 
     strcpy(url, ctx->postUrl);
     strcat(url, "/gettokens");
-//    http.dumpReqHeader(true);
-//    http.dumpResHeader(true);
+    http.dumpReqHeader(true);
+    http.dumpResHeader(true);
     int ret;
     
     //GET data
@@ -71,10 +73,21 @@
     map.put("uuid", ctx->uuid);
     printf("\nTrying to post data...\n");
     ret = http.post(url, map, &inText);
+    Yodiwo_Plegma_PairingServerTokensResponse_t tokens;
     if (!ret)
     {
-      printf("Executed POST successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
+        printf("Executed POST successfully - read %d characters\n", strlen(str));
+        printf("Result: %s\n", str);
+        int jret = Yodiwo_Plegma_PairingServerTokensResponse_FromJson(str, strlen(str), &tokens);
+        if (jret == Yodiwo_JsonSuccessParse) {
+            ctx->token1 = tokens.token1;
+            ctx->token2 = tokens.token2;
+            return 0;
+        } else {
+            printf("error parsing response");
+            return -2;
+        }
+      
       
     }
     else
@@ -84,3 +97,4 @@
     return ret;
     
 }
+
--- a/pairing_backend.h	Tue Sep 01 10:23:13 2015 +0000
+++ b/pairing_backend.h	Tue Sep 01 12:01:50 2015 +0000
@@ -6,6 +6,10 @@
 extern "C" {
 #endif
 
+#include <stdint.h>
+#include "jsmn.h"
+#include "yodiwo_helpers.h"
+
 typedef void (*onPaired_callback)(char *nodeKey, char *secretKey);
 
 typedef struct
@@ -20,6 +24,12 @@
     onPaired_callback onPaired;
 } pairing_context;
 
+typedef struct
+{
+    char *token1;
+    char *token2; 
+} tokens_t;
+
 int pairing_context_init_with_defaults(pairing_context *ctx, onPaired_callback callback);
 
 int start_pairing(pairing_context *ctx);
@@ -29,8 +39,6 @@
 
 
 
-
-
 #ifdef __cplusplus
 }
 #endif