Created
May 26, 2014 19:45
-
-
Save wgbartley/b1b3bb17af3e4a919d27 to your computer and use it in GitHub Desktop.
Spark Uptime Test
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
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