int M2XStreamClient::updateLocation(const char* feedId, const char* name, const char* latitude, const char* longitude, const char* elevation) { if (_client->connect(_host, _port)) { #ifdef DEBUG printf("Connected to M2X server!\n"); #endif int length = write_location_data(&_null_print, name, latitude, longitude, elevation); _client->print("PUT /v1/feeds/"); print_encoded_string(_client, feedId); _client->println("/location HTTP/1.0"); writeHttpHeader(length); write_location_data(_client, name, latitude, longitude, elevation); } else { #ifdef DEBUG printf("ERROR: Cannot connect to M2X server!\n"); #endif return E_NOCONNECTION; } return readStatusCode(true); }
int M2XStreamClient::readLocation(const char* feedId, location_read_callback callback, void* context) { if (_client->connect(_host, _port)) { #ifdef DEBUG printf("Connected to M2X server!\n"); #endif _client->print("GET /v1/feeds/"); print_encoded_string(_client, feedId); _client->println("/location HTTP/1.0"); writeHttpHeader(-1); } else { #ifdef DEBUG printf("ERROR: Cannot connect to M2X server!\n"); #endif return E_NOCONNECTION; } int status = readStatusCode(false); if (status == 200) { readLocation(callback, context); } close(); return status; }
size_t HTTPFetchHeadParser::readFirstLine() { size_t endLinePos = headerString.find_first_of("\r\n"); if(endLinePos == std::string::npos) throw HTTPFetchHeadParserException(); size_t pos = 0; pos = readVersion(pos); pos = readStatusCode(pos); pos = readReasonPhrase(pos, endLinePos); return pos; }
int M2XStreamClient::send(const char* feedId, const char* streamName, const char* value) { if (_client->connect(_host, _port)) { #ifdef DEBUG printf("Connected to M2X server!\n"); #endif writeSendHeader(feedId, streamName, // 6 for "value=" _null_print.print(value) + 6); _client->print("value="); print_encoded_string(_client, value); } else { #ifdef DEBUG printf("ERROR: Cannot connect to M2X server!\n"); #endif return E_NOCONNECTION; } return readStatusCode(true); }