Created
May 27, 2019 10:41
-
-
Save alistairjevans/038fece8f6cd00c31fe94fb1c0330b19 to your computer and use it in GitHub Desktop.
Sensor data keep-alives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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