ผม จะ query ข้อความเพื่อเเจ้งเตือนไปที่ไลน์ เเต่ติดปัญหาตรง query ไม่ทราบว่า ติดอะไรครับ
ปล. ผมยังไมไ่ด้กด upload โค้ดลงบอร์ดนะครับ เเค่กด verify เท่านั้นส่วนของ ip,pass,user ผมลบออกนะครับ เเต่ตอนกด verify ยังใส่อยู่
#include <WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include "SimpleTimer.h"
#include <TridentTD_LineNotify.h>
// set buttonPIN
const int buttonPin1 = 12;
const int buttonPin2 = 13;
int button1 = 0;
int button2 = 0;
#define LINE_TOKEN "TOKEN" //ยังไม่ใส่
const char* ssid = "";
const char* password = "";
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(); // IP ของ MySQL server
char dbuser[] = ""; // MySQL username
char dbpassword[] = ""; // MySQL password
// SELECT query (เงื่อนไขในการ Query ข้อมูล)
char query[] = "SELECT date_format(New_book.New_book_reservation.create_date,"%h:%i:%p") as date,New_book.New_book_rooms.name as room_name,
New_book_user.name as username,phone,topic
FROM New_book.New_book_rooms
inner join New_book.New_book_reservation
on New_book.New_book_rooms.id = New_book.New_book_reservation.room_id
inner join New_book.New_book_user
on New_book.New_book_user.id = New_book.New_book_reservation.room_id
where New_book.New_book_rooms.name = 'PCS-streel meeting room' and end ='+07:00' > NOW()
ORDER BY New_book.New_book_reservation.create_date DESC limit 1"; //บรรทัดนี้ขึ้น error นะครับ
WiFiClient client;
MySQL_Connection conn((Client *)&client);
void linenoti(){
if(button1 == HIGH){
LINE.notify(connDB());
}
}
void setup() {
Serial.begin(115200);
delay(10);
timer.setInterval(100,connDB);
timer.setInterval(1000,linenoti);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
// Connect to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid); // print ssid ที่ connect ได้
LINE.setToken(LINE_TOKEN); //LINE
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected to ");
Serial.print("IP : ");
Serial.println(WiFi.localIP());
Serial.println("Your device is now online to internet.");
Serial.println("");
//MySQL Connection
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, dbuser, dbpassword)) {
delay(1000);
Serial.println("MySQL Connected.");
}
else
Serial.println("Connection failed.");
//conn.close();
}
void connDB(){
row_values *row = NULL;
//String head_count ;
delay(10000);
Serial.println("Selecting data.");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(query); // Execute the query
column_names *columns = cur_mem->get_columns(); // Fetch the columns
// Read the row (we are only expecting the one)
do {
row = cur_mem->get_next_row();
if (row != NULL) {
Serial.println(row->values[1]); //ค่าที่ SELECT ได้จากฐานข้อมูล
}
} while (row != NULL);
delete cur_mem; // Deleting the cursor also frees up memory used
}
void loop() {
timer.run();
// DigiReadPin
button1 = digitalRead(buttonPin1);
button2 = digitalRead(buttonPin2);
}
Copy error full มาวางหน่อยครับ
สวัสดีครับ เป็นไงบ้างเคสนี้ อัพเดทกันหน่อยครับผม