ARM mbed M2X API Client: The ARM mbed client library is used to send/receive data to/from AT&T's M2X service from mbed LPC1768 microcontrollers.

Dependents:   m2x-demo-all M2X_MTS_ACCEL_DEMO M2X_MTS_Accel M2X_K64F_ACCEL ... more

Files at this revision

API Documentation at this revision

Comitter:
NetArc
Date:
Sun Jan 04 05:26:33 2015 +0000
Parent:
13:0d574742208f
Child:
15:2610823f7f2e
Commit message:
Added support for path prefix for app-flow

Changed in this revision

M2XStreamClient.cpp Show annotated file Show diff for this revision Revisions of this file
M2XStreamClient.h Show annotated file Show diff for this revision Revisions of this file
M2XStreamClient_template.h Show annotated file Show diff for this revision Revisions of this file
--- a/M2XStreamClient.cpp	Tue Dec 09 14:36:16 2014 +0000
+++ b/M2XStreamClient.cpp	Sun Jan 04 05:26:33 2015 +0000
@@ -29,11 +29,13 @@
                                  const char* key,
                                  int case_insensitive,
                                  const char* host,
-                                 int port) : _client(client),
+                                 int port,
+                                 const char* path_prefix) : _client(client),
                                              _key(key),
                                              _case_insensitive(case_insensitive),
                                              _host(host),
                                              _port(port),
+                                             _path_prefix(path_prefix),
                                              _null_print() {
 }
 
@@ -42,7 +44,10 @@
                                       const char* query) {
   if (_client->connect(_host, _port)) {
     DBGLN("%s", "Connected to M2X server!");
-    _client->print("GET /v2/devices/");
+    _client->print("GET ");
+    if (_path_prefix)
+        _client->print(_path_prefix);
+    _client->print("/v2/devices/");
     print_encoded_string(_client, deviceId);
     _client->print("/streams/");
     print_encoded_string(_client, streamName);
@@ -75,7 +80,10 @@
                                   void* context) {
   if (_client->connect(_host, _port)) {
     DBGLN("%s", "Connected to M2X server!");
-    _client->print("GET /v2/devices/");
+    _client->print("GET ");
+    if (_path_prefix)
+        _client->print(_path_prefix);
+    _client->print("/v2/devices/");
     print_encoded_string(_client, deviceId);
     _client->println("/location HTTP/1.0");
 
@@ -143,7 +151,10 @@
 void M2XStreamClient::writePutHeader(const char* deviceId,
                                      const char* streamName,
                                      int contentLength) {
-  _client->print("PUT /v2/devices/");
+  _client->print("PUT ");
+  if (_path_prefix)
+    _client->print(_path_prefix);
+  _client->print("/v2/devices/");
   print_encoded_string(_client, deviceId);
   _client->print("/streams/");
   print_encoded_string(_client, streamName);
@@ -155,7 +166,10 @@
 void M2XStreamClient::writeDeleteHeader(const char* deviceId,
                                         const char* streamName,
                                         int contentLength) {
-  _client->print("DELETE /v2/devices/");
+  _client->print("DELETE ");
+  if (_path_prefix)
+    _client->print(_path_prefix);
+  _client->print("/v2/devices/");
   print_encoded_string(_client, deviceId);
   _client->print("/streams/");
   print_encoded_string(_client, streamName);
--- a/M2XStreamClient.h	Tue Dec 09 14:36:16 2014 +0000
+++ b/M2XStreamClient.h	Sun Jan 04 05:26:33 2015 +0000
@@ -78,7 +78,8 @@
                   const char* key,
                   int case_insensitive = 1,
                   const char* host = kDefaultM2XHost,
-                  int port = kDefaultM2XPort);
+                  int port = kDefaultM2XPort,
+                  const char* path_prefix = NULL);
 
   // Push data stream value using PUT request, returns the HTTP status code
   template <class T>
@@ -169,6 +170,7 @@
   int _case_insensitive;
   const char* _host;
   int _port;
+  const char* _path_prefix;
   NullPrint _null_print;
 
   // Writes the HTTP header part for updating a stream value
--- a/M2XStreamClient_template.h	Tue Dec 09 14:36:16 2014 +0000
+++ b/M2XStreamClient_template.h	Sun Jan 04 05:26:33 2015 +0000
@@ -57,7 +57,10 @@
     DBGLN("%s", "Connected to M2X server!");
     int length = write_multiple_values(&_null_print, streamNum, names,
                                        counts, ats, values);
-    _client->print("POST /v2/devices/");
+    _client->print("POST ");
+    if (_path_prefix)
+      _client->print(_path_prefix);
+    _client->print("/v2/devices/");
     print_encoded_string(_client, deviceId);
     _client->println("/updates HTTP/1.0");
     writeHttpHeader(length);
@@ -113,7 +116,10 @@
 
     int length = write_location_data(&_null_print, name, latitude, longitude,
                                      elevation);
-    _client->print("PUT /v2/devices/");
+    _client->print("PUT ");
+    if (_path_prefix)
+      _client->print(_path_prefix);
+    _client->print("/v2/devices/");
     print_encoded_string(_client, deviceId);
     _client->println("/location HTTP/1.0");