Page 144 - 2
P. 144
}
// 두개를 입력으로 설정
pinMode(mail, INPUT);
pinMode(shock, INPUT);
}
// 핀 상태를 읽어 메세지 전송
void loop() {
state = digitalRead(mail);
if (state){
sendToPushover(" 투서가 도착했네요");
state = LOW;
}
state2 = digitalRead(shock);
if (state2){
sendToPushover(" 충격이 가해졌네요");
state2 = LOW;
}
}
// 푸시오버 서버에 메세지 전송
void sendToPushover(String Msg) {
Msg = Msg+"&title="+Title;
length = Msg.length()+81;
if (client.connect("api.pushover.net", 80)) {
client.println("POST /1/messages.json HTTP/1.1");
client.println("Host: api.pushover.net");
client.println("Connection: close\r\nContent-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.print(length);
client.println("\r\n");
client.print("token="+apiToken+"&user="+userKey+"&message="+Msg);
client.stop();
}
}
- 144 -