/*
Line Token Notify
ESP32
01/6/2024
*/
#include <WiFi.h>
//#include <HTTPClient.h> // ***
#include <ArtronShop_LineNotify.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
#define LINE_TOKEN "Z32L3HgskI9yoW4KuB6KvnTSzUveg4O5lM02zaXExwx" // LINE Token
int sw2 = 2; int senser_2 = 0;
#define pinA0 A0 // pin VP // *** analog pin A
float val_A0 = 0;
//float val_flo = 0.00;
bool send_finish = false; // send_finish = true;
//////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode(sw2, INPUT_PULLUP);
pinMode(A0, INPUT);
// *** WiFi setup ///////////////////////////////////
Serial.println("----------------------------------");
Serial.print("Connecting to WiFi : ");
WiFi.begin(ssid, password, 6);
//WiFi.begin("Wokwi-GUEST", "", 6); // ssid, password, 6 ************
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////////////////////////////////////////////////////
} // *** setup
///////////////////////////////////////////////////////
void loop() {
/*//HTTP/////////////////////////////////////////////
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http; // *************************
http.begin("http://nitify-api.line.me/api/nitify");
}
*/ //////////////////////////////////////////////////
val_A0 = analogRead(A0); delay(10);
val_A0 = float((val_A0*100)/4095);
Serial.print(val_A0); Serial.println(" %");
// begin senser_2 to LINE ////////////////////////////////////////////////////
senser_2 = digitalRead(sw2); delay(10);
if(senser_2 == 0) {
if (!send_finish) { // *** !send_finish
LINE.begin(LINE_TOKEN); // *** or LINE.begin(TOKEN1); LINE.setToken("Token 1"); ... LINE.setToken("Token 2");
///* // ++ sticker and PIC //////////////////////////////
//int pack = 446; int stic = 1988;
LINE_Notify_Massage_Option_t option; // *** option or optionPic , https://developers.line.biz/en/docs/messaging-api/sticker-list/ , https://pic.in.th/?lang=th
option.sticker.package_id = 6325 ; // Package ID
option.sticker.id = 10979917 ; // Sticker ID
//optionPic.image.url = "https://img2.pic.in.th/pic/IMG20230921232431.jpeg";
/*// ++ Map
option.map.service = LONGDO_MAP; // Longdo Map
// option.map.service = GOOGLE_MAP; // Google Map
option.map.lat = 13.91024;
option.map.lng = 100.51108;
option.map.zoom = 20; // *** 1 - 20
// option.map.api_key = "Google Map API Key"; // API Key ---- Google Map
*/
//*/ ///////////////////////////////////////////////////
String msg = String(val_A0); // *int to string , String msg = "TEXT"; ***
if (LINE.send("ระดับน้ำ: " + msg + " %", &option)) { // *** if (LINE.send("TEXT", &option)) { *** or &optionPic
Serial.println("Send LINE-notify successful");
send_finish = true; //******
} else {
Serial.printf("Send notify fail. Check token (code: %d)\n", LINE.status_code); // *** code: 401 your token fail
}
} // *** !send_finish
else {
send_finish = false; //******
}
} // *** senser_2
// end senser_2 to LINE ///////////////////////////////////////////////////
/* *** test string to int or float ****************
delay(100);
String msg = "123.45";
String inString = msg;
float msgNum = inString.toFloat(); // or int msgInt = inString.toInt(); ***
Serial.print(msgNum); Serial.println(" : int or folat msgNum");
// Serial.printf("check your token (code: %d)\n", msgNum);
*/
delay(1000);
} // *** END loop .....................................
///////////////////////////////////////////////////////////////////////////////////////
// https://www.artronshop.co.th/article/124/esp32-line-notify
// https://developers.line.biz/en/docs/messaging-api/sticker-list/
// 446 1988
// 8522 16581269
// 6325 10979917
/*
LINE.begin(LINE_TOKEN); // LINE Notify
LINE_Notify_Massage_Option_t option; // สร้างตัวแปร option
// https://developers.line.biz/en/docs/messaging-api/sticker-list/
option.sticker.package_id = 446; // Package ID
option.sticker.id = 1988; // ID
Z32L3HgskI9yoW4KuB6KvnTSzUveg4O5lM02zaXExwx
Z32L3HgskI9yoW4KuB6KvnTSzUveg4O5lM02zaXExwx
*/