Skip to content

Instantly share code, notes, and snippets.

@wgbartley
Created June 2, 2014 03:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wgbartley/0724c8def5c671c797bf to your computer and use it in GitHub Desktop.
Save wgbartley/0724c8def5c671c797bf to your computer and use it in GitHub Desktop.
Spark-Uptime
char srvIP[] = "256.256.256.256";
char srvHost[] = "myhost.mydomain.tld";
int srvPort = 80;
char srvPath[] = "/?l=test1";
void setup() {
delay(5000);
pinMode(D7, OUTPUT);
}
void loop() {
httpGetRequest(srvIP, srvHost, srvPort, srvPath);
Spark.sleep(SLEEP_MODE_DEEP, 1800);
}
void httpGetRequest(char* ip, char* hostname, int port, char* url) {
delay(5000);
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