Created
June 2, 2014 03:22
-
-
Save wgbartley/0724c8def5c671c797bf to your computer and use it in GitHub Desktop.
Spark-Uptime
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[] = "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