fork download
  1. void Line_Notify1(String message1) ;
  2. #include <ESP8266.h>
  3. #define WIFI_SSID "Patpicha" /////////////*************แก้
  4. #define WIFI_PASSWORD "12345678"////////**************แก้
  5. #define LINE_TOKEN_PIR "Icu0eaYwZRgBVA8NqEhvkQN7GwdrnmR5n3okjzQbb1Z" ////***************แก้
  6. #define PirPin D6
  7.  
  8. String message1 = "%E0%B8%88%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%A2%E0%B8%A1%E0%B8%B2%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%A5%E0%B8%B0%E0%B8%9A%E0%B8%B1%E0%B8%81%E0%B8%AA%E0%B8%B1%E0%B8%AA%E0%B8%AA%E0%B8%AA!!!!!";//****************แก้
  9. bool beep_state = false;
  10. bool send_state = false;
  11. uint32_t ts, ts1, ts2;
  12. void setup() {
  13. Serial.begin(115200);
  14. Serial.println();
  15. pinMode(PirPin, INPUT);
  16. pinMode(LED_BUILTIN, OUTPUT);
  17. digitalWrite(LED_BUILTIN, HIGH);
  18. // dht.begin();
  19. Serial.println("connecting");
  20. WiFi.mode(WIFI_STA);
  21. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  22. Serial.print("connecting");
  23. while (WiFi.status() != WL_CONNECTED) {
  24. Serial.print(".");
  25. delay(500);
  26. }
  27. Serial.println();
  28. Serial.print("connected: ");
  29. Serial.println(WiFi.localIP());
  30. delay(10000);
  31. Serial.println("Pir Ready!!");
  32. //read_sensor();
  33. ts = ts1 = ts2 = millis();
  34. }
  35. void loop() {
  36. ts = millis();
  37. if (WiFi.status() == WL_CONNECTED) {
  38. digitalWrite(LED_BUILTIN, LOW);
  39. } else {
  40. digitalWrite(LED_BUILTIN, HIGH);
  41. }
  42.  
  43. if ((ts - ts1 >= 5000) && (beep_state == true)) {
  44. beep_state = false;
  45. }
  46.  
  47. if ((digitalRead(PirPin) == HIGH) && (beep_state == false) && (WiFi.status() == WL_CONNECTED)) {
  48. while (digitalRead(PirPin) == HIGH) delay(100);
  49. Serial.println("Detect !");
  50. Line_Notify1(message1);
  51. beep_state = true;
  52. }
  53. delay(10);
  54. }
  55. void Line_Notify1(String message) {
  56. WiFiClientSecure client;
  57.  
  58. if (!client.connect("notify-api.line.me", 443))
  59. {
  60. Serial.println("connection failed");
  61. delay(2000);
  62. return;
  63. }
  64. String req = "";
  65. req += "POST /api/notify HTTP/1.1\r\n";
  66. req += "Host: notify-api.line.me\r\n";
  67. req += "Authorization: Bearer " + String(LINE_TOKEN_PIR) + "\r\n";
  68. req += "Cache-Control: no-cache\r\n";
  69. req += "User-Agent: ESP8266\r\n";
  70. req += "Content-Type: application/x-www-form-urlencoded\r\n";
  71. req += "Content-Length: " + String(String("message=" + message1).length()) + "\r\n";
  72. req += "\r\n";
  73. req += "message=" + message1;
  74. // Serial.println(req);
  75. client.print(req);
  76. delay(20);
  77. while (client.connected()) {
  78. String line = client.readStringUntil('\n');
  79. if (line == "\r") {
  80. break;
  81. }
  82. }
  83. }
  84.  
  85.  
Success #stdin #stdout 0.04s 25484KB
stdin
Standard input is empty
stdout
void Line_Notify1(String message1) ;
#include <ESP8266.h>
#define WIFI_SSID "Patpicha" /////////////*************แก้
#define WIFI_PASSWORD "12345678"////////**************แก้
#define LINE_TOKEN_PIR "Icu0eaYwZRgBVA8NqEhvkQN7GwdrnmR5n3okjzQbb1Z" ////***************แก้
#define PirPin D6

String message1 = "%E0%B8%88%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%A2%E0%B8%A1%E0%B8%B2%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%A5%E0%B8%B0%E0%B8%9A%E0%B8%B1%E0%B8%81%E0%B8%AA%E0%B8%B1%E0%B8%AA%E0%B8%AA%E0%B8%AA!!!!!";//****************แก้
bool beep_state = false;
bool send_state = false;
uint32_t ts, ts1, ts2;
void setup() {
  Serial.begin(115200);
  Serial.println();
  pinMode(PirPin, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
 // dht.begin();
  Serial.println("connecting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  delay(10000);
  Serial.println("Pir Ready!!");
  //read_sensor();
  ts = ts1 = ts2 = millis();
}
void loop() {
  ts = millis();
  if (WiFi.status() == WL_CONNECTED) {
    digitalWrite(LED_BUILTIN, LOW);
  } else {
    digitalWrite(LED_BUILTIN, HIGH);
  }
    
  if ((ts - ts1 >= 5000) && (beep_state == true)) {
    beep_state = false;
  } 
  
  if ((digitalRead(PirPin) == HIGH) && (beep_state == false) && (WiFi.status() == WL_CONNECTED)) {
    while (digitalRead(PirPin) == HIGH) delay(100);
    Serial.println("Detect !");
    Line_Notify1(message1);
    beep_state = true;
  }
  delay(10);
}
void Line_Notify1(String message) {
  WiFiClientSecure client;
 
  if (!client.connect("notify-api.line.me", 443)) 
{
    Serial.println("connection failed");
    delay(2000);
    return;
  }
  String req = "";
  req += "POST /api/notify HTTP/1.1\r\n";
  req += "Host: notify-api.line.me\r\n";
  req += "Authorization: Bearer " + String(LINE_TOKEN_PIR) + "\r\n";
  req += "Cache-Control: no-cache\r\n";
  req += "User-Agent: ESP8266\r\n";
  req += "Content-Type: application/x-www-form-urlencoded\r\n";
  req += "Content-Length: " + String(String("message=" + message1).length()) + "\r\n";
  req += "\r\n";
  req += "message=" + message1;
  // Serial.println(req);
  client.print(req);
  delay(20);
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      break;
    }
  }
}