Modified M2XStreamClient
Fork of M2XStreamClient-JMF by
Diff: M2XStreamClient.h
- Revision:
- 23:f32837239193
- Parent:
- 22:4d895e732765
- Child:
- 24:6a5ba4cfa19a
--- a/M2XStreamClient.h Wed Jun 15 12:36:55 2016 +0000 +++ b/M2XStreamClient.h Sun Sep 11 02:16:44 2016 +0000 @@ -120,7 +120,7 @@ const char* timestamp, int index, void* context); - + typedef void (*m2x_command_read_callback)(const char* id, const char* name, int index, @@ -230,6 +230,12 @@ // response is only parsed when the HTTP status code is 200 int readLocation(const char* deviceId, location_read_callback callback, void* context); + + // Delete location information for a device. The HTTP status code is + // returned,response is only parsed when the HTTP status code is 200 + int M2XStreamClient::deleteLocations(const char* deviceId, + const char* from, const char* end); + #endif /* M2X_ENABLE_READER */ // Delete values from a data stream @@ -362,6 +368,9 @@ void writeDeleteHeader(const char* deviceId, const char* streamName, int contentLength); + void writeDeleteLocationHeader(const char* deviceId, + int contentLength); + // Writes HTTP header lines including M2X API Key, host, content // type and content length(if the body exists) void writeHttpHeader(int contentLength); @@ -820,6 +829,19 @@ writeHttpHeader(contentLength); } +void M2XStreamClient::writeDeleteLocationHeader(const char* deviceId, + int contentLength) { + _client->print("DELETE "); + if (_path_prefix) { _client->print(_path_prefix); } + _client->print("/v2/devices/"); + _client->print(deviceId); + _client->print("/location/waypoints/"); + _client->println(" HTTP/1.0"); + + writeHttpHeader(contentLength); +} + + void M2XStreamClient::writeHttpHeader(int contentLength) { _client->println(USER_AGENT); _client->print("X-M2X-KEY: "); @@ -1415,6 +1437,21 @@ return status; } +int M2XStreamClient::deleteLocations(const char* deviceId, + const char* from, const char* end) { + if (_client->connect(_host, _port)) { + DBGLN("%s", "Connected to M2X server!"); + int length = write_delete_values(&_null_print, from, end); + writeDeleteLocationHeader(deviceId, length); + write_delete_values(_client, from, end); + } else { + DBGLN("%s", "ERROR: Cannot connect to M2X server!"); + return E_NOCONNECTION; + } + + return readStatusCode(true); +} + int M2XStreamClient::listCommands(const char* deviceId, m2x_command_read_callback callback, void* context,