watch using the RSSI of Bluetooth

Dependencies:   BaseUsbHost ConfigFile EthernetInterface HTTPClient-long mbed-rtos mbed

Committer:
va009039
Date:
Sun Jan 20 09:22:31 2013 +0000
Revision:
0:600fe65e7c88
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:600fe65e7c88 1 #include "CosmClient.h"
va009039 0:600fe65e7c88 2
va009039 0:600fe65e7c88 3 CosmClient::CosmClient(const char* apiKey, const char* feedID)
va009039 0:600fe65e7c88 4 {
va009039 0:600fe65e7c88 5 if (apiKey) {
va009039 0:600fe65e7c88 6 m_apiKey = apiKey;
va009039 0:600fe65e7c88 7 }
va009039 0:600fe65e7c88 8 if (feedID) {
va009039 0:600fe65e7c88 9 m_feedID = feedID;
va009039 0:600fe65e7c88 10 }
va009039 0:600fe65e7c88 11 }
va009039 0:600fe65e7c88 12
va009039 0:600fe65e7c88 13 void CosmClient::clear()
va009039 0:600fe65e7c88 14 {
va009039 0:600fe65e7c88 15 m_buf.clear();
va009039 0:600fe65e7c88 16 }
va009039 0:600fe65e7c88 17
va009039 0:600fe65e7c88 18 void CosmClient::add(const char* id, int value, const char* format)
va009039 0:600fe65e7c88 19 {
va009039 0:600fe65e7c88 20 char buf[16];
va009039 0:600fe65e7c88 21 snprintf(buf, sizeof(buf), format, value);
va009039 0:600fe65e7c88 22 m_buf += string(id) + "," + buf + "\n";
va009039 0:600fe65e7c88 23 }
va009039 0:600fe65e7c88 24
va009039 0:600fe65e7c88 25 void CosmClient::add(const char* id, float value, const char* format)
va009039 0:600fe65e7c88 26 {
va009039 0:600fe65e7c88 27 char buf[16];
va009039 0:600fe65e7c88 28 snprintf(buf, sizeof(buf), format, value);
va009039 0:600fe65e7c88 29 m_buf += string(id) + "," + buf + "\n";
va009039 0:600fe65e7c88 30 }
va009039 0:600fe65e7c88 31
va009039 0:600fe65e7c88 32 void CosmClient::add(int id, float value, const char* format)
va009039 0:600fe65e7c88 33 {
va009039 0:600fe65e7c88 34 char buf[16];
va009039 0:600fe65e7c88 35 snprintf(buf, sizeof(buf), "%d", id);
va009039 0:600fe65e7c88 36 m_buf += buf;
va009039 0:600fe65e7c88 37 snprintf(buf, sizeof(buf), format, value);
va009039 0:600fe65e7c88 38 m_buf += string(",") + buf + "\n";
va009039 0:600fe65e7c88 39 }
va009039 0:600fe65e7c88 40
va009039 0:600fe65e7c88 41 int CosmClient::update()
va009039 0:600fe65e7c88 42 {
va009039 0:600fe65e7c88 43 HTTPClient http;
va009039 0:600fe65e7c88 44 char str[16];
va009039 0:600fe65e7c88 45 HTTPText inText(str, sizeof(str));
va009039 0:600fe65e7c88 46 HTTPText outText(const_cast<char*>(m_buf.c_str()));
va009039 0:600fe65e7c88 47 string url = "http://api.cosm.com/v2/feeds/" + m_feedID + ".csv?key=" + m_apiKey;
va009039 0:600fe65e7c88 48 //string url = "http://api.cosm.com/v2/feeds/" + m_feedID + "?_method=put&key=" + m_apiKey;
va009039 0:600fe65e7c88 49 int ret = http.put(url.c_str(), outText, &inText);
va009039 0:600fe65e7c88 50 return ret;
va009039 0:600fe65e7c88 51 }