void Line_Notify(String message) ;
#include <ESP8266WiFi.h>
// Config connect WiFi
#define WIFI_SSID "xxxx"
#define WIFI_PASSWORD "xxxx"
// Line config
#define LINE_TOKEN "xxxxx"
#define SW D2
String message = "%E0%B9%82%E0%B8%94%E0%B8%99%E0%B8%81%E0%B8%94";
void setup() {
pinMode(SW, INPUT);
Serial.begin(9600);
WiFi.mode(WIFI_STA);
// connect to wifi.
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());
}
void loop() {
if (digitalRead(SW) == HIGH) {
while(digitalRead(SW) == HIGH) delay(10);
Serial.println("Enter !");
Line_Notify(message);
// Serial.println();
}
delay(10);
}
void Line_Notify(String message) {
WiFiClientSecure client;
if (!client.connect("notify-api.line.me", 443)) {
Serial.println("connection failed");
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) + "\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=" + message).length()) + "\r\n";
req += "\r\n";
req += "message=" + message;
// Serial.println(req);
client.print(req);
delay(20);
// Serial.println("-------------");
while(client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
break;
}
//Serial.println(line);
}
// Serial.println("-------------");
}
อีกวิธีการส่ง LINE ที่แนะนำ สามารถส่งภาษาไทย และง่ายกว่านี้ โดยใช้ IFTTT
ยังไม่พบ comport เช็คว่าลงไดรเวอร์เรียบร้อยแล้ว
NodeMCU ถ้าซื้อกับทางร้านจะตรวจเช็คให้แบบละเอียดก่อนส่ง หรือถ้ามีปัญหาก็รับประกันให้มั่นใจได้
ขอเลขที่สั่งซื้อด้วยครับ
Arduino Uno R3 เป็น atmel ส่วน NodeMCU เป็น CP2102 เป็นไดรเวอร์คนละตัวกับ arduino uno
ต้องลงไดรเวอร์ก่อน ดาวน์โหลดได้จากลิงค์นี้ครับ http://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
สำหรับ Arduino Uno R3 SMD และ NodeMCU V3 จะใช้ชิฟ CH340G อันนี้เป็นไดรเวอร์ตัวเดียวกันครับ