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.
Fork of M2XStreamClient by
Diff: M2XStreamClient.h
- Revision:
- 10:4ce9eba38dbe
- Parent:
- 3:2b527486e864
- Child:
- 13:0d574742208f
--- a/M2XStreamClient.h Sun Sep 07 17:56:18 2014 +0000
+++ b/M2XStreamClient.h Wed Sep 10 13:07:34 2014 +0000
@@ -48,10 +48,18 @@
static const int E_INVALID = -4;
static const int E_JSON_INVALID = -5;
+/*
+ * +type+ indicates the value type: 1 for string, 2 for number
+ * NOTE that the value type here only contains a hint on how
+ * you can use the value. Even though 2 is returned, the value
+ * is still stored in (const char *), and atoi/atof is needed to
+ * get the actual value
+ */
typedef void (*stream_value_read_callback)(const char* at,
const char* value,
int index,
- void* context);
+ void* context,
+ int type);
typedef void (*location_read_callback)(const char* name,
double latitude,
@@ -72,9 +80,9 @@
const char* host = kDefaultM2XHost,
int port = kDefaultM2XPort);
- // Post data stream value, returns the HTTP status code
+ // Push data stream value using PUT request, returns the HTTP status code
template <class T>
- int post(const char* feedId, const char* streamName, T value);
+ int put(const char* feedId, const char* streamName, T value);
// Post multiple values to M2X all at once.
// +feedId+ - id of the feed to post values
@@ -87,9 +95,8 @@
// be the some of all values in +counts+, for the first +counts[0]+
// items, the values belong to the first stream, for the following
// +counts[1]+ number of items, the values belong to the second stream,
- // etc. Note timestamps are optional, if a value does not havee timestamp,
- // we can simply put NULL here, or we can put NULl for +ats+, meaning
- // none of the values has a timestamp
+ // etc. Notice that timestamps are required here: you must provide
+ // a timestamp for each value posted.
// +values+ - Values to post. This works the same way as +ats+, the
// first +counts[0]+ number of items contain values to post to the first
// stream, the succeeding +counts[1]+ number of items contain values
@@ -140,6 +147,23 @@
// response is only parsed when the HTTP status code is 200
int readLocation(const char* feedId, location_read_callback callback,
void* context);
+
+ // Delete values from a data stream
+ // You will need to provide from and end date/time strings in the ISO8601
+ // format "yyyy-mm-ddTHH:MM:SS.SSSZ" where
+ // yyyy: the year
+ // mm: the month
+ // dd: the day
+ // HH: the hour (24 hour format)
+ // MM: the minute
+ // SS.SSS: the seconds (to the millisecond)
+ // NOTE: the time is given in Zulu (GMT)
+ // M2X will delete all values within the from to end date/time range.
+ // The status code is 204 on success and 400 on a bad request (e.g. the
+ // timestamp is not in ISO8601 format or the from timestamp is not less than
+ // or equal to the end timestamp.
+ int deleteValues(const char* feedId, const char* streamName,
+ const char* from, const char* end);
private:
Client* _client;
const char* _key;
@@ -149,9 +173,13 @@
NullPrint _null_print;
// Writes the HTTP header part for updating a stream value
- void writePostHeader(const char* feedId,
- const char* streamName,
- int contentLength);
+ void writePutHeader(const char* feedId,
+ const char* streamName,
+ int contentLength);
+ // Writes the HTTP header part for deleting stream values
+ void writeDeleteHeader(const char* feedId,
+ const char* streamName,
+ int contentLength);
// Writes HTTP header lines including M2X API Key, host, content
// type and content length(if the body exists)
void writeHttpHeader(int contentLength);
