สวัสดีค่ะ คือหนูทำโปรเจคเกี่ยวกับขยะเต็มถังแจ้งเตือนในไลน์ ตอนนี้ติดปัญหาตรงที่ข้อความไม่แจ้งเข้าในไลน์อะค่ะ ใครก็ได้ช่วยหนูหน่อยจนปัญญาแล้วค่ะT^T
หนูใช้ESP8266 ตัวNodeMcu V3(ESP-12E,USB CH340)ค่ะ กับSensor IR
การต่อวงจร คือ 3V >> VCC
G >> G
D6 >> OUT
นี่คือโค้ดค่ะ
void Line_Notify1(String message1) ;
#include
#define WIFI_SSID "xxxxxx" /////////////*************แก้
#define WIFI_PASSWORD "xxxxxx"////////**************แก้
#define LINE_TOKEN_PIR "xxxxxx" ////***************แก้
#define PirPin D6
String message1 = "%E0%B8%A1%E0%B8%B5%E0%B8%88%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%A2%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%B2";//****************แก้
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;
}
}
}
ตอนอัปโหลดโค้ดมันจะขึ้นว่า
ICACHE : 32768 - flash instruction cache
IROM : 349164 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 28317 / 32768 - code in IRAM (IRAM_ATTR, ISRs...)
DATA : 1496 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 1680 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 25776 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 380657 bytes (36%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28952 bytes (35%) of dynamic memory, leaving 52968 bytes for local variables. Maximum is 81920 bytes.
esptool.py v3.0
Serial port COM5
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 30:83:98:80:fa:b0
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 384816 bytes to 284437...
Writing at 0x00000000... (5 %)
Writing at 0x00004000... (11 %)
Writing at 0x00008000... (16 %)
Writing at 0x0000c000... (22 %)
Writing at 0x00010000... (27 %)
Writing at 0x00014000... (33 %)
Writing at 0x00018000... (38 %)
Writing at 0x0001c000... (44 %)
Writing at 0x00020000... (50 %)
Writing at 0x00024000... (55 %)
Writing at 0x00028000... (61 %)
Writing at 0x0002c000... (66 %)
Writing at 0x00030000... (72 %)
Writing at 0x00034000... (77 %)
Writing at 0x00038000... (83 %)
Writing at 0x0003c000... (88 %)
Writing at 0x00040000... (94 %)
Writing at 0x00044000... (100 %)
Wrote 384816 bytes (284437 compressed) at 0x00000000 in 25.3 seconds (effective 121.6 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
หนูไม่รู้ว่ามันขึ้นแบบนี้คือผ่านหรือไม่ผ่าน แต่ในไลน์ไม่มีอะไรแจ้งมาเลยค่ะ หนูก็เลยอยากทราบค่ะว่าหนูพลาดตรงไหนหรือต้องแก้อะไรยังไงตรงไหนคะ ช่วยหนูหน่อยค่าา
**ที่จริงโค้ดข้างต้นใช้ในโปรเจคแจ้งเตือนในไลน์เมื่อมีจดหมายไปรษณีย์ค่ะ หนูลองเอามาดัดแปลงกับโปรเจคของหนูดูเผื่อได้
ลองดูตัวอย่างใช้งาน esp8266 กับ line ดังนี้
https://www.allnewstep.com/b/289
และมีคอร์สสอนทั้งหมดแบบละเอียดที่นี่ www.arduinoall.net ลองเข้ามาเล่นนะครับ