I don't suppose you have a uip sample somewhere that does an http PUT?

-Eric
(p.s. slacklab seems down atm)
Moderator: shard7
// init wishield variables etc
void loop()
{
start = millis();
for (int i = 0; i < NUMBER_OF_CTS; i++)
{
for (int n = 0; n < numberOfSamples; n++)
{
// sample, filter, accumulate voltage and CT current readings
} // End of V/I samples loop
// frob the power values a little more
} // End of CTs loop
// Check if it's time to send an external update of averages
if (millis() >= updateTime) {
// Do another update PACHUBE_UPDATE_INTERVAL from now
updateTime += PACHUBE_UPDATE_INTERVAL;
// Get average power info since last external update
// today for the wiserver I do:
response_done = 0;
// This uses a PUT to send the 3 values up to pachube
postPachube.submit();
// We know we have net traffic now; give server_task() some concentrated love
do {
WiServer.server_task();
delay(10);
} while (!response_done);
}
#define PACKETSIZE 1024
void someOtherFunc()
{
...
//post the data to Pachube
sendPUTPachube("173.203.98.29", 80, "www.pachube.com", NULL, 2557, phase1, phase2);
...
}
bool sendPUTPachube(char *ipAddr, int port, char* hostName, char* URL, int feed, float phase1, float phase2)
{
int retval;
struct sockaddr_in server;
struct hostent *hp;
int conn_socket;
char *pSendBuf = new char[PACKETSIZE];
if(!pSendBuf) {
printf("could not allocate packet memory.\n");
return false;
}
char *pRecvBuf = new char[PACKETSIZE];
if(!pRecvBuf) {
printf("could not allocate packet memory.\n");
return false;
}
hp = gethostbyname(ipAddr);
if(!hp) {
printf("Client cannot resolve address [%s].\n", ipAddr);
return false;
}
// Copy the resolved information into the sockaddr_in structure
memset(&server, 0, sizeof(server));
memcpy(&(server.sin_addr), hp->h_addr, hp->h_length);
server.sin_family = hp->h_addrtype;
server.sin_port = htons(port);
conn_socket = socket(AF_INET, SOCK_STREAM ,0); // Open a socket
if (conn_socket < 0) {
printf("Error Opening socket\n");
return false;
}
//printf("Client connecting to: %s.\n", hp->h_name);
if(-1 == connect(conn_socket, (struct sockaddr*)&server, sizeof(server))) {
printf("connect(conn_socket) failed.\n");
return false;
}
// fill the packet with 'data'
memset(pSendBuf, '0', PACKETSIZE * sizeof(char));
_snprintf_s(pSendBuf, PACKETSIZE, PACKETSIZE, "PUT /api/%d.csv HTTP/1.1\nHost: www.pachube.com\nX-PachubeApiKey: <YOUR_PACHUBE_KEY>\nContent-Length: 1\nConnection: close\n\n%f,%f,%f\n", feed, phase1, phase2, phase1 + phase2);
//printf("%s\n", pSendBuf);
retval = send(conn_socket, pSendBuf, strlen(pSendBuf), 0);
if (-1 == retval) {
printf("send(conn_socket) failed.\n");
return false;
}
retval = recv(conn_socket, pRecvBuf, PACKETSIZE,0 );
if (-1 == retval) {
printf("recv(conn_socket) failed.\n");
//shutdown(conn_socket, SHUT_RDWR);
closesocket(conn_socket);
return false;
}
/*
printf("\n======================================================================\n");
if(NULL != strstr(pRecvBuf, "HTTP/1.1 200 OK"))
printf("Received OK\n");
else
printf("Did not receive OK\n");
printf("\n======================================================================\n");
printf("sendPUTPachube Received:\n");
printf("%s\n", pRecvBuf);
printf("\n======================================================================\n");
*/
//shutdown(conn_socket, SHUT_RDWR);
closesocket(conn_socket);
delete pSendBuf;
delete pRecvBuf;
return true;
}
Users browsing this forum: No registered users and 1 guest