Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sensor data keep-alives
void sendData(unsigned long timestamp, double speed)
{
char body[64];
int success = 1;
// If we're not connected, open the connection.
if(!client.connected())
{
success = client.connect(SERVER, SERVERPORT);
}
if(success)
{
// Empty the buffer
// (I still don't really care about the response)
while(client.read() != -1);
memset(body, 0, 64);
sprintf(body, "milliseconds=%lu&speed=", timestamp);
dtostrf(speed, 2, 3, &body[strlen(body)]);
int bodyLength = strlen(body);
client.println("POST /data/providereading HTTP/1.1");
client.print("Host: ");
client.print(SERVER);
client.print(":");
client.println(SERVERPORT);
// This tells the server we want to leave the
// connection open.
client.println("Connection: keep-alive");
client.print("Content-Length: ");
client.println(bodyLength);
client.println("Content-Type: application/x-www-form-urlencoded");
client.println();
client.print(body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.