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