Skip to content

Instantly share code, notes, and snippets.

@wgbartley
Created May 26, 2014 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgbartley/b1b3bb17af3e4a919d27 to your computer and use it in GitHub Desktop.
Save wgbartley/b1b3bb17af3e4a919d27 to your computer and use it in GitHub Desktop.
Spark Uptime Test
char srvIP[] = "198.199.86.22";
char srvHost[] = "spark.wgb.me";
int srvPort = 80;
char srvPath[] = "/logger/?l=uptime-test";
void setup() {
delay(5000);
pinMode(D7, OUTPUT);
RGB.control(true);
RGB.color(0, 0, 0);
}
void loop() {
httpGetRequest(srvIP, srvHost, srvPort, srvPath);
Spark.sleep(60);
}
void httpGetRequest(char* ip, char* hostname, int port, char* url) {
digitalWrite(D7, HIGH);
char line[255];
TCPClient client;
if(client.connect(ip, port)) {
strcpy(line, "GET ");
strcat(line, url);
strcat(line, " HTTP/1.1");
client.println(line);
delay(100);
strcpy(line, "Host: ");
strcat(line, hostname);
client.println(line);
delay(100);
strcpy(line, "Content-Length: 0");
client.println(line);
delay(100);
client.println();
delay(100);
client.flush();
delay(100);
client.stop();
delay(250);
}
digitalWrite(D7, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment