Quantcast
Channel: Wireless Connectivity
Viewing all articles
Browse latest Browse all 116964

Forum Post: RE: COSMCLOUDAPP

$
0
0

Hi Mike, I call this routine from the main code:

long http_server_update(void)
{

long lerr;
sockaddr tSocketAddr;
long ulClientSocket;
long SentLen;
unsigned long ulServerIpAddr;
char Request[CC3000_MINIMAL_TX_SIZE];
char sData[50];
char sTemp[50];
unsigned long port;
int len;
int iBytesReceived;
memcpy(Request, 0, sizeof(Request));
memcpy(sData, 0, sizeof(sData));
memcpy(sTemp, 0, sizeof(sTemp));

/*
* Example output:
*
* PUT /api/v2/feeds/84547.csv HTTP/1.1
* Host: api.cosm.com
* X-Apikey: gogtzh2WIzLN-yNqSkkL1aZBasmSAK
* User-Agent: contrary

*Content-Length: 7
* Content-Type: text/csv
* Connection: close
* 0,87
* 1,33
*/

* cosm IP address expressed as long and concatenated
ulServerIpAddr = 2915787293; // gets unwound into correct hex bytes and flipped to little endian
//test idiot cleanup - debugger breaks cause lots of left open sockets
closesocket(0);
closesocket(1);
closesocket(2);
closesocket(3);

// Connect to Cosm
//
tSocketAddr.sa_family = AF_INET;
//
// Web HTTP Port
//
port = htons(80);
memcpy(&tSocketAddr.sa_data[0], &port, sizeof(unsigned short));
// IP addr cosm
ulServerIpAddr = htonl(ulServerIpAddr);

memcpy(&tSocketAddr.sa_data[2], (unsigned char*)&ulServerIpAddr, 4);
// Connect Socket
ulClientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

lerr = connect(ulClientSocket, &tSocketAddr, sizeof(tSocketAddr));
_no_operation();
if(lerr != ESUCCESS)
{
closesocket(ulClientSocket);
return lerr;
}
//
//make data transmission packet
//

sprintf(Request, "PUT /v2/feeds/%s.csv HTTP/1.1\r\n", FEEDID);

strcat(Request, "Host: api.cosm.com\r\n");
strcat(Request, "Accept: */*\r\n");
strcat(Request, "X-PachubeApiKey: ");
sprintf (sTemp, "%s\r\n", APIKEY);
strcat(Request, sTemp);
// memcpy(sTemp, 0, sizeof(sTemp));
sprintf(sData, "0, %d",TEMPERATURE);
strcat(sData,"\r\n");
sprintf(sTemp,"1, %d",VOLUME);
strcat(sTemp,"\r\n");
strcat(sData,sTemp);
len = strlen(sData);
// last pieces of the HTTP PUT request:
sprintf(sTemp, "Content-Length: %d\r\n\r\n", len);
strcat(Request,sTemp);
strcat(Request,sData);

turnLedOn(CC3000_CLIENT_CONNECTED_IND);
SentLen = send(ulClientSocket, Request, strlen(Request), 0);

if(SentLen <= 0)
{
return SentLen;
}
memcpy(sTemp, 0, sizeof(sTemp));

iBytesReceived = recv(ulClientSocket, sTemp, 50, 0);

turnLedOn(CC3000_SENDING_DATA_IND);
closesocket(ulClientSocket);
{
turnLedOn(CC3000_UNUSED1_IND);
__delay_cycles(100000);
toggleLed(CC3000_UNUSED1_IND);
__delay_cycles(100000);
__no_operation();
}
return ESUCCESS;
}

Obviously this is only the csv version but it sure does work well when the CC3000 is working, which I find is a random event in the best of circumstances. One thing I have consistently random(?!?) problems with is connect(). Sometimes it works and sometimes it doesn't.

Wish TI would publish a V1.8 patch that got around the connect() failure when wlan_start and wlan_stop have been performed.


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>