watch using the RSSI of Bluetooth
Dependencies: BaseUsbHost ConfigFile EthernetInterface HTTPClient-long mbed-rtos mbed
Diff: CosmClient/CosmClient.cpp
- Revision:
- 0:600fe65e7c88
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CosmClient/CosmClient.cpp Sun Jan 20 09:22:31 2013 +0000 @@ -0,0 +1,51 @@ +#include "CosmClient.h" + +CosmClient::CosmClient(const char* apiKey, const char* feedID) +{ + if (apiKey) { + m_apiKey = apiKey; + } + if (feedID) { + m_feedID = feedID; + } +} + +void CosmClient::clear() +{ + m_buf.clear(); +} + +void CosmClient::add(const char* id, int value, const char* format) +{ + char buf[16]; + snprintf(buf, sizeof(buf), format, value); + m_buf += string(id) + "," + buf + "\n"; +} + +void CosmClient::add(const char* id, float value, const char* format) +{ + char buf[16]; + snprintf(buf, sizeof(buf), format, value); + m_buf += string(id) + "," + buf + "\n"; +} + +void CosmClient::add(int id, float value, const char* format) +{ + char buf[16]; + snprintf(buf, sizeof(buf), "%d", id); + m_buf += buf; + snprintf(buf, sizeof(buf), format, value); + m_buf += string(",") + buf + "\n"; +} + +int CosmClient::update() +{ + HTTPClient http; + char str[16]; + HTTPText inText(str, sizeof(str)); + HTTPText outText(const_cast<char*>(m_buf.c_str())); + string url = "http://api.cosm.com/v2/feeds/" + m_feedID + ".csv?key=" + m_apiKey; + //string url = "http://api.cosm.com/v2/feeds/" + m_feedID + "?_method=put&key=" + m_apiKey; + int ret = http.put(url.c_str(), outText, &inText); + return ret; +}