Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface FXOS8700Q HTTPClient HTTPD MQTTS SDFileSystem YodiwoPlegma mbed-rpc mbed-rtos mbed wolfSSL
Diff: pairing_backend.cpp
- Revision:
- 0:00797f1ebe04
- Child:
- 1:c5abc450140c
diff -r 000000000000 -r 00797f1ebe04 pairing_backend.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pairing_backend.cpp Tue Sep 01 10:23:13 2015 +0000
@@ -0,0 +1,86 @@
+#include "pairing_backend.h"
+#include "HTTPClient.h"
+#include "mbed.h"
+#include "rtos.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/";
+ ctx->uuid = "1337CNode";
+ ctx->name = "Nodas";
+ ctx->onPaired = callback;
+ return 0;
+}
+
+#define STACK_SIZE 24000
+
+void get_tokens_thread(void const *arg);
+
+int start_pairing(pairing_context *ctx)
+{
+ printf("getting tokens from server\n");
+ Thread t(get_tokens_thread, ctx, osPriorityNormal, STACK_SIZE);
+ while (t.get_state() != Thread::Inactive) {
+// printf("yielding... %d\n", t.get_state());
+// Thread::yield();
+// Thread::wait(1000);
+ }
+ printf("thread ended?\n");
+ return 0;
+}
+
+char str[512];
+char url[100];
+
+void get_tokens_thread(void const *arg)
+{
+ printf("in thread\n");
+ __get_tokens((pairing_context *)arg);
+}
+
+int __get_tokens(pairing_context *ctx)
+{
+
+ strcpy(url, ctx->postUrl);
+ strcat(url, "/gettokens");
+// http.dumpReqHeader(true);
+// http.dumpResHeader(true);
+ int ret;
+
+ //GET data
+// printf("\nTrying to fetch page...\n");
+// ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
+// if (!ret)
+// {
+// printf("Page fetched successfully - read %d characters\n", strlen(str));
+// printf("Result: %s\n", str);
+// }
+// else
+// {
+// printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+// }
+
+ //POST data
+ HTTPMap map;
+ HTTPText inText(str, 512);
+ map.put("name", ctx->name);
+ map.put("uuid", ctx->uuid);
+ printf("\nTrying to post data...\n");
+ ret = http.post(url, map, &inText);
+ if (!ret)
+ {
+ printf("Executed POST successfully - read %d characters\n", strlen(str));
+ printf("Result: %s\n", str);
+
+ }
+ else
+ {
+ printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+ }
+ return ret;
+
+}