watch using the RSSI of Bluetooth

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

CosmClient/CosmClient.cpp

Committer:
va009039
Date:
2013-01-20
Revision:
0:600fe65e7c88

File content as of revision 0:600fe65e7c88:

#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;
}