Created
December 24, 2014 15:09
-
-
Save ktknest/8fe3afd0f88b92620001 to your computer and use it in GitHub Desktop.
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
TCPClient client; | |
char server[] = "MY_SERVER_HOST"; | |
const int SENSOR_PIN = A7; | |
int value = 0; | |
boolean isPush = false; | |
void setup() { | |
Serial.begin( 9600 ); | |
Serial.println("Serial OK"); | |
} | |
void loop() { | |
value = analogRead(SENSOR_PIN); // 0 - 4095 | |
if (value < 4000) { | |
Serial.println(value); | |
if (isPush == false) { | |
isPush = true; | |
// API実行 | |
message(); | |
} | |
} else if (isPush == true) { | |
isPush = false; | |
Serial.println("Released"); | |
} | |
delay(100); | |
} | |
void message() { | |
Serial.println("## connecting..."); | |
if (client.connect(server, 80)) | |
{ | |
Serial.println("connected"); | |
client.println("GET /MY_API_URL HTTP/1.1"); | |
client.println("Host: MY_SERVER_HOST"); | |
client.println("Connection: close"); | |
client.println(); | |
while (client.connected()) { | |
if (client.available()) { | |
char c = client.read(); | |
Serial.print(c); | |
} | |
} | |
client.stop(); | |
Serial.println(); | |
Serial.println("Disconnecting."); | |
} | |
else | |
{ | |
Serial.println("connection failed"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment