ปัญหา line notify ไม่แจ้งเตือน

สอบถามหน่อยครับ เนื่องจากก่อนหน้านี้ใช้ wifi เเจ้งเตือน line notify ได้ปกติ เเต่พอ เอา ble กับ line chat bot มาผนวกกัน wifi ก็เหมือน connect ได้นะครับ เเต่ Line notify เหมือนมันจะไม่แจ้งเตือน อยากทราปัญหาว่าเกิดจากอะไรครับ ไม่มี error เเต่เหมือนจะเป็นบัค

#include <WiFi.h>
#include <iSYNC.h>
#include "SparkFun_SGP30_Arduino_Library.h" // 0x58 Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "TinyGPS++.h"
#include "SoftwareSerial.h"
#include "SimpleTimer.h"
#include <TinyGPS++.h>
#include <TridentTD_LineNotify.h>
WiFiClient client;
iSYNC iSYNC(client);


#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

String ssid = "ITI_SHOP2";
String pass = "12345678";

String iSYNC_USERNAME = "stanutty1123";
String iSYNC_KEY = "5fb2aa195e614c07a2d8a206";
String iSYNC_AUTH = "5fb2aa015e614c07a2d8a204"; //auth project
#define line_token1   "RNeq6SkFENTEiQhus2ZhMo2krwP0ljw1eDeWRezLPRw"
#define line_token2   "ZEq8qHwUdIOVBfjF2wlAWp1Oh6AmDMC4ejky5edodTf"
#define line_token3   ""

float ppm;
float RS_gasc = 0;
float ratioc = 0;
float sensorValuec = 0;
float sensor_voltc = 0;
float R0c = 7200.0;
float xc=0;

float sensor_volt;
float RS_gas; // Get value of RS in a GAS
float R0 = 15000; //example value of R0. Replace with your own
float ratio; // Get ratio RS_GAS/RS_air
float LPG_PPM;
float x=0;
LiquidCrystal_I2C lcd(0x3F, 20, 4);   //Module IIC/I2C Interface บางรุ่นอาจจะใช้ 0x3f
SGP30 mySensor; //create an object of the SGP30 class

SoftwareSerial serial_connection(16, 17); //RX=pin 10, TX=pin 11
TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
SimpleTimer timer; // ประกาศให้ฟังก์ชัน ทำงาน

#define LedblynkGreen 19  
const int LedblynkRed = 18;                     // ใช้ไฟ LED สีฟ้า ของบอร์ด MCU ESP32 ให้มีสัญญาณไฟกระพริบ ตาม Code ที่เขียน
const int AP_Config = 5;                // ใช้เป็นปุ่มกด เพื่อเข้า AP Config ได้ตามความต้องการของผู้ใช้
#define buzzer  23

void callback(char* topic, byte* payload, unsigned int length) {
  String msg = "";
  Serial.print("[iSYNC]-> ");
  for (int i = 0; i < length; i++){
    msg+=(char)payload[i];
    Serial.print((char)payload[i]);
  }
  Serial.println();
  if(msg.startsWith("LINE:"))msg = msg.substring(5);

  /* command control */
  if(msg.equals("lpg")){
      iSYNC.mqPub(iSYNC_KEY,"Lpg :" +String (LPG_PPM) +" ppb");   //Publish
       
  }else if(msg.equals("พิกัด")){
      iSYNC.mqPub(iSYNC_KEY,"ที่นี่คือ "+String (gps.location.lat(), 6)+", "+String (gps.location.lng(), 6));   //Publish
         
  }else if(msg.equals("co2")){
    iSYNC.mqPub(iSYNC_KEY,"Co2 :" +String (mySensor.CO2) +" ppm");
    
    }else if(msg.equals("tvoc")){
      iSYNC.mqPub(iSYNC_KEY,"TVOC :" +String (mySensor.TVOC) +" ppb"); 
      
      }else if(msg.equals("co")){
         iSYNC.mqPub(iSYNC_KEY,"Co :" +String (ppm) +" ppm");
      }   
}

void connectMQTT(){
  while(!iSYNC.mqConnect()){
    Serial.println("Reconnect MQTT...");
    delay(3000);
  }
  iSYNC.mqPub(iSYNC_KEY,"สวัสดี");   //Publish on Connect
  iSYNC.mqSubProject(); //subscribe all key in your project
  iSYNC.mqSub(iSYNC_KEY); //subscribe key
}

void setup() {
  Serial.begin(115200);
  Serial.println(iSYNC.getVersion());
   SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
    timer.setInterval(3000, readSensor); // ตั้งเวลาให้อ่านทุก 3 วิ
  timer.setInterval(360000, toline); // ตั้งเวลาให้อ่านทุก 60 วิ
  lcd.begin();
  lcd.backlight(); 
  Wire.begin();
 
  serial_connection.begin(9600);//This opens up communications to the GPS
  //************************************************LINE NOTIFY*********************
  Serial.println(LINE.getVersion());
  LINE.setToken(line_token1); 
  LINE.setToken(line_token2); 
  LINE.setToken(line_token3);
  String message = "Messeage to LINE";

  pinMode(buzzer, OUTPUT); 
  pinMode(LedblynkGreen, OUTPUT); 
  pinMode(LedblynkRed, OUTPUT);      //กำหนดโหมดใช้งานให้กับขา Ledblynk เป็นขา สัญญาณไฟ ในสภาวะต่างๆ
  pinMode(AP_Config, INPUT_PULLUP);//กำหนดโหมดใช้งานให้กับขา AP_Config เป็นขา กดปุ่ม ค้าง เพื่อตั้งค่า AP config

  //Initialize sensor
  if (mySensor.begin() == false) {
    Serial.println("No SGP30 Detected. Check connections.");
    while (1);
  }
  //Initializes sensor for air quality readings
  //measureAirQuality should be called in one second increments after a call to initAirQuality
  mySensor.initAirQuality();
// ให้ LED ทั้งหมดดับก่อน
  digitalWrite(LedblynkRed, LOW);//ให้หลอด LED สีฟ้าดับก่อน
  digitalWrite(LedblynkGreen, LOW);//ให้หลอด LED สีฟ้าดับก่อน
  digitalWrite(buzzer, HIGH);
 

  iSYNC.begin(ssid,pass);
  iSYNC.mqInit(iSYNC_USERNAME,iSYNC_AUTH);
  iSYNC.MQTT->setCallback(callback);
  connectMQTT();
}
  
void loop() {
  const int sensorValuec = A5;
   sensor_voltc = sensorValuec/1024*5.0;
   RS_gasc = (5.0-sensor_voltc)/sensor_voltc;
   ratioc = RS_gasc/R0c; //Replace R0 with the value found using the sketch above
    xc = 1538.46 * ratioc;
    ppm = pow(x,-1.709);
  //lpg
    int sensorValue = analogRead(A0);
    sensor_volt=(float)sensorValue/1024*5.0;
    RS_gas = (5.0-sensor_volt)/sensor_volt;
    ratio = RS_gas/R0;
    x = 1000*ratio ;
    LPG_PPM = pow(x,-1.431);//LPG PPM
  
  if (!iSYNC.mqConnected())connectMQTT();
  iSYNC.mqLoop();
 while(serial_connection.available())//While there are characters to come from the GPS
  {
    gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
  }
  if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  {
    //Get the latest info from the gps object which it derived from the data sent by the GPS unit
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println("");
  } 
  if(mySensor.CO2>1500 || mySensor.TVOC>2000 ||LPG_PPM>500 || ppm>30){
  digitalWrite(buzzer, LOW);
  delay(500);
  digitalWrite(buzzer, HIGH);
  delay(500);
  digitalWrite(LedblynkRed, HIGH);
  digitalWrite(LedblynkGreen, LOW);
 // lcd.setCursor(0,3);lcd.print(" STATUS : UNSAFE   ");
  }else{
    digitalWrite(buzzer, HIGH);
    digitalWrite(LedblynkGreen, HIGH);
    digitalWrite(LedblynkRed, LOW);
   // lcd.setCursor(0,3);lcd.print(" STATUS : SAFE     ");
    }
  if(mySensor.CO2>1500 && mySensor.TVOC>2000 ||LPG_PPM>500 || ppm>30){
  LINE.setToken(line_token1);
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");
  LINE.notify("อันตรายมีแก๊สเกินกำหนด");
  
    LINE.setToken(line_token2); 
      LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
      LINE.notify("Latitude: "+String(gps.location.lat(), 6));
      LINE.notify(" CO2 :  "+String (mySensor.CO2)+" ppm");
      LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
      LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
      LINE.notify(" CO: "+String (ppm) +" ppm");
       LINE.notify("อันตรายมีแก๊สเกินกำหนด");

     LINE.setToken(line_token3); 
      LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
      LINE.notify("Latitude: "+String(gps.location.lat(), 6));
      LINE.notify(" CO2 :  "+String (mySensor.CO2)+" ppm");
      LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
      LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
      LINE.notify(" CO: "+String (ppm) +" ppm");
       LINE.notify("อันตรายมีแก๊สเกินกำหนด");
       }
  SerialBT.print("CO2 :  "+String (mySensor.CO2)+" ppm");
  SerialBT.println("TVOC :  "+String (mySensor.TVOC)+" ppb"); 
  SerialBT.println("LPG :  "+String (LPG_PPM)+" ppb"); 
  timer.run();
  //SerialBT.print(LPG_PPM);
}
void readSensor() {

  //First fifteen readings will be
  //CO2: 400 ppm  TVOC: 0 ppb
  //measure CO2 and TVOC levels
  
  mySensor.measureAirQuality();
  Serial.print("CO2: ");
  Serial.print(mySensor.CO2);
  Serial.print(" ppm\tTVOC: ");
  Serial.print(mySensor.TVOC);
  Serial.println(" ppb");
  Serial.print("LPG PPM = ");
  Serial.println(LPG_PPM);
   Serial.print("CO = ");
    Serial.println(ppm);
  lcd.setCursor(0,0);
  lcd.print(" CO2: ");
  lcd.print(mySensor.CO2);
  lcd.print(" ppm");
  lcd.setCursor(0,1);
  lcd.print(" TVOC: ");
  lcd.print(mySensor.TVOC);
  lcd.print(" ppb");
  lcd.setCursor(0,2);
  lcd.print(" LPG : "); lcd.print(LPG_PPM); lcd.print(" ppb");
  lcd.setCursor(0,3);
  lcd.print(" CO :"); lcd.print(ppm); lcd.print(" ppm");
  //lcd.print("Longitude:"); lcd.print(gps.location.lng(), 6);
  //lcd.setCursor(0,3);lcd.println("\n"); 
  //lcd.setCursor(0,3);lcd.println("Longitude:");lcd.print(gps.location.lng(), 6);
  //delay(1000); //Wait 1 secondd

}
void toline() //timer notify 60min
{ 

   if(mySensor.CO2<1500 || mySensor.TVOC<2000 ||LPG_PPM<500 || ppm<30){
  
 LINE.setToken(line_token1); LINE.notify("ปลอดภัยดี");
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");
  
 LINE.setToken(line_token2); LINE.notify("ปลอดภัยดี");
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");

 LINE.setToken(line_token3); LINE.notify("ปลอดภัยดี");
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");
    }
}

แยกระหว่าง 2 โค้ตที่เอามาผสมกันให้ดูหน่อยครับ

#include <WiFi.h>
#include <iSYNC.h>
#include "SparkFun_SGP30_Arduino_Library.h" // 0x58 Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "TinyGPS++.h"
#include "SoftwareSerial.h"
#include "SimpleTimer.h"
#include <TinyGPS++.h>
#include <TridentTD_LineNotify.h>            //               เรียกใช้ไลบารี่ line notify                   //
WiFiClient client;
iSYNC iSYNC(client);


#include "BluetoothSerial.h"                     //             Bluetooth                                            //
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;
//          ------------------------         จบการเรียกใช้ bluetooth                  ---------------------------------- //

// ---------------------------------------         ส่สวนของ Line chatbot (ใช้ของ Isync) ---------///
String ssid = "xxxxxxxxxxxxxxxxxxxx";
String pass = "xxxxxxxxxxxxxxxxxxxx";

String iSYNC_USERNAME = "xxxxxxxxxxxxxxxxxxxx";
String iSYNC_KEY = "xxxxxxxxxxxxxxxxxxxx";
String iSYNC_AUTH = "xxxxxxxxxxxxxxxxxxxx"; //auth project

//----------------------------------------------- จบการเรียกใช้ line chatbot ---------------------------------------
//-------------------------------------------- กำหนด ไลน์ token ------------------------------------------
#define line_token1   "xxxxxxxxxxxxxxxxxxxx"
#define line_token2   "xxxxxxxxxxxxxxxxxxxx"
#define line_token3   ""
// ---------------------------------------------------------------------------------------------------------
float ppm;
float RS_gasc = 0;
float ratioc = 0;
float sensorValuec = 0;
float sensor_voltc = 0;
float R0c = 7200.0;
float xc=0;

float sensor_volt;
float RS_gas; // Get value of RS in a GAS
float R0 = 15000; //example value of R0. Replace with your own
float ratio; // Get ratio RS_GAS/RS_air
float LPG_PPM;
float x=0;

LiquidCrystal_I2C lcd(0x3F, 20, 4);   //Module IIC/I2C Interface บางรุ่นอาจจะใช้ 0x3f
SGP30 mySensor; //create an object of the SGP30 class

SoftwareSerial serial_connection(16, 17); //RX=pin 10, TX=pin 11
TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
SimpleTimer timer; // ประกาศให้ฟังก์ชัน ทำงาน

#define LedblynkGreen 19  
const int LedblynkRed = 18;                     // ใช้ไฟ LED สีฟ้า ของบอร์ด MCU ESP32 ให้มีสัญญาณไฟกระพริบ ตาม Code ที่เขียน
const int AP_Config = 5;                // ใช้เป็นปุ่มกด เพื่อเข้า AP Config ได้ตามความต้องการของผู้ใช้
#define buzzer  23

//****************--------------------------------------------- ฟังชั่น ISYNC การโต้ตอบ Line chatbot----------------------********
void callback(char* topic, byte* payload, unsigned int length) {
  String msg = "";
  Serial.print("[iSYNC]-> ");
  for (int i = 0; i < length; i++){
    msg+=(char)payload[i];
    Serial.print((char)payload[i]);
  }
  Serial.println();
  if(msg.startsWith("LINE:"))msg = msg.substring(5);

  /* command control */
  if(msg.equals("lpg")){
      iSYNC.mqPub(iSYNC_KEY,"Lpg :" +String (LPG_PPM) +" ppb");   //Publish
       
  }else if(msg.equals("พิกัด")){
      iSYNC.mqPub(iSYNC_KEY,"ที่นี่คือ "+String (gps.location.lat(), 6)+", "+String (gps.location.lng(), 6));   //Publish
         
  }else if(msg.equals("co2")){
    iSYNC.mqPub(iSYNC_KEY,"Co2 :" +String (mySensor.CO2) +" ppm");
    
    }else if(msg.equals("tvoc")){
      iSYNC.mqPub(iSYNC_KEY,"TVOC :" +String (mySensor.TVOC) +" ppb"); 
      
      }else if(msg.equals("co")){
         iSYNC.mqPub(iSYNC_KEY,"Co :" +String (ppm) +" ppm");
      }   
}
// --------------------------------------------- จบส่วนการตั้งค่าการโต้ตอบ line chatbot ----------

// -------------------------------------- การ Connect Mqtt ----------------------------------
void connectMQTT(){
  while(!iSYNC.mqConnect()){
    Serial.println("Reconnect MQTT...");
    delay(3000);
  }
  iSYNC.mqPub(iSYNC_KEY,"สวัสดี");   //Publish on Connect
  iSYNC.mqSubProject(); //subscribe all key in your project
  iSYNC.mqSub(iSYNC_KEY); //subscribe key
}
////////////------------------------------------------จบส่วนของ ISYNC -------------------------------------------------
void setup() {
  Serial.begin(115200);
  Serial.println(iSYNC.getVersion());
----------------------------------------------------------------------- Config Bluetooth -------------------------
   SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
----------------------------------------------------------------------- จบ Config Bluetooth -------------------------
    timer.setInterval(3000, readSensor); // ตั้งเวลาให้อ่านทุก 3 วิ
  timer.setInterval(360000, toline); // ตั้งเวลาให้อ่านทุก 60 วิ
  lcd.begin();
  lcd.backlight(); 
  Wire.begin();
 
  serial_connection.begin(9600);//This opens up communications to the GPS
  //************************************************LINE NOTIFY*********************
  WiFi.begin( SSID, PASSWORD );
  while(!WiFi.isConnected()) delay(400);
  Serial.println( WiFi.localIP());
  Serial.println(LINE.getVersion());
  LINE.setToken(line_token1); 
  LINE.setToken(line_token2); 
  LINE.setToken(line_token3);
  String message = "Messeage to LINE";
  //************************************************จบ LINE NOTIFY*********************
  pinMode(buzzer, OUTPUT); 
  pinMode(LedblynkGreen, OUTPUT); 
  pinMode(LedblynkRed, OUTPUT);      //กำหนดโหมดใช้งานให้กับขา Ledblynk เป็นขา สัญญาณไฟ ในสภาวะต่างๆ
  pinMode(AP_Config, INPUT_PULLUP);//กำหนดโหมดใช้งานให้กับขา AP_Config เป็นขา กดปุ่ม ค้าง เพื่อตั้งค่า AP config

  //Initialize sensor
  if (mySensor.begin() == false) {
    Serial.println("No SGP30 Detected. Check connections.");
    while (1);
  }
  //Initializes sensor for air quality readings
  //measureAirQuality should be called in one second increments after a call to initAirQuality
  mySensor.initAirQuality();
// ให้ LED ทั้งหมดดับก่อน
  digitalWrite(LedblynkRed, LOW);//ให้หลอด LED สีฟ้าดับก่อน
  digitalWrite(LedblynkGreen, LOW);//ให้หลอด LED สีฟ้าดับก่อน
  digitalWrite(buzzer, HIGH);
 
// ----------------------------------------- ISYNC -----------------------------------------
  iSYNC.begin(ssid,pass);
  iSYNC.mqInit(iSYNC_USERNAME,iSYNC_AUTH);
  iSYNC.MQTT->setCallback(callback);
  connectMQTT();
}
  
void loop() {
  const int sensorValuec = A5;
   sensor_voltc = sensorValuec/1024*5.0;
   RS_gasc = (5.0-sensor_voltc)/sensor_voltc;
   ratioc = RS_gasc/R0c; //Replace R0 with the value found using the sketch above
    xc = 1538.46 * ratioc;
    ppm = pow(x,-1.709);
  //lpg
    int sensorValue = analogRead(A0);
    sensor_volt=(float)sensorValue/1024*5.0;
    RS_gas = (5.0-sensor_volt)/sensor_volt;
    ratio = RS_gas/R0;
    x = 1000*ratio ;
    LPG_PPM = pow(x,-1.431);//LPG PPM

  ///////////// --------------  ถ้า ISYNC ไม่ Connect จะกลับไปที่ void connect Mqtt ด้านบน  ------

  if (!iSYNC.mqConnected())connectMQTT();
  iSYNC.mqLoop();

///-----------------------------------------------------------------------------------------------------///

///                                                   --- GPS --
 while(serial_connection.available())//While there are characters to come from the GPS
  {
    gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
  }
  if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  {
    //Get the latest info from the gps object which it derived from the data sent by the GPS unit
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println("");
  } 
//---                                          จบส่วน GPS --
  if(mySensor.CO2>1500 || mySensor.TVOC>2000 ||LPG_PPM>500 || ppm>30){
  digitalWrite(buzzer, LOW);
  delay(500);
  digitalWrite(buzzer, HIGH);
  delay(500);
  digitalWrite(LedblynkRed, HIGH);
  digitalWrite(LedblynkGreen, LOW);
 // lcd.setCursor(0,3);lcd.print(" STATUS : UNSAFE   ");
  }else{
    digitalWrite(buzzer, HIGH);
    digitalWrite(LedblynkGreen, HIGH);
    digitalWrite(LedblynkRed, LOW);
   // lcd.setCursor(0,3);lcd.print(" STATUS : SAFE     ");
    }
// ---------------------------------- การเเจ้งเตือนส่วนไลน์  ------------------
  if(mySensor.CO2>1500 && mySensor.TVOC>2000 ||LPG_PPM>500 || ppm>30){
  LINE.setToken(line_token1);
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");
  LINE.notify("อันตรายมีแก๊สเกินกำหนด");
  
    LINE.setToken(line_token2); 
      LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
      LINE.notify("Latitude: "+String(gps.location.lat(), 6));
      LINE.notify(" CO2 :  "+String (mySensor.CO2)+" ppm");
      LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
      LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
      LINE.notify(" CO: "+String (ppm) +" ppm");
       LINE.notify("อันตรายมีแก๊สเกินกำหนด");

     LINE.setToken(line_token3); 
      LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
      LINE.notify("Latitude: "+String(gps.location.lat(), 6));
      LINE.notify(" CO2 :  "+String (mySensor.CO2)+" ppm");
      LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
      LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
      LINE.notify(" CO: "+String (ppm) +" ppm");
       LINE.notify("อันตรายมีแก๊สเกินกำหนด");
       }
// ------------------------------------------------------------ จบส่วนการแจ้งเตือนไลน์

/// --------------------------------------- ส่งค่า bluetooth ไปแสดงที่ App mit invertor -------
  SerialBT.print("CO2 :  "+String (mySensor.CO2)+" ppm");
  SerialBT.println("TVOC :  "+String (mySensor.TVOC)+" ppb"); 
  SerialBT.println("LPG :  "+String (LPG_PPM)+" ppb"); 

//------------------------------------------ จบส่วนของ bluetooth --------------------------------
  timer.run();
  //SerialBT.print(LPG_PPM);
}
void readSensor() {

  //First fifteen readings will be
  //CO2: 400 ppm  TVOC: 0 ppb
  //measure CO2 and TVOC levels
  
  mySensor.measureAirQuality();
  Serial.print("CO2: ");
  Serial.print(mySensor.CO2);
  Serial.print(" ppm\tTVOC: ");
  Serial.print(mySensor.TVOC);
  Serial.println(" ppb");
  Serial.print("LPG PPM = ");
  Serial.println(LPG_PPM);
   Serial.print("CO = ");
    Serial.println(ppm);
  lcd.setCursor(0,0);
  lcd.print(" CO2: ");
  lcd.print(mySensor.CO2);
  lcd.print(" ppm");
  lcd.setCursor(0,1);
  lcd.print(" TVOC: ");
  lcd.print(mySensor.TVOC);
  lcd.print(" ppb");
  lcd.setCursor(0,2);
  lcd.print(" LPG : "); lcd.print(LPG_PPM); lcd.print(" ppb");
  lcd.setCursor(0,3);
  lcd.print(" CO :"); lcd.print(ppm); lcd.print(" ppm");
  //lcd.print("Longitude:"); lcd.print(gps.location.lng(), 6);
  //lcd.setCursor(0,3);lcd.println("\n"); 
  //lcd.setCursor(0,3);lcd.println("Longitude:");lcd.print(gps.location.lng(), 6);
  //delay(1000); //Wait 1 secondd

}
void toline() //timer notify 60min             
  // ------------------------------  ส่วนนี้เป็นการส่งแจ้งเตือนไลน์ทุกๆ 1ชม. -----------------

{ 

   if(mySensor.CO2<1500 || mySensor.TVOC<2000 ||LPG_PPM<500 || ppm<30){
  
 LINE.setToken(line_token1); LINE.notify("ปลอดภัยดี");
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");
  
 LINE.setToken(line_token2); LINE.notify("ปลอดภัยดี");
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");

 LINE.setToken(line_token3); LINE.notify("ปลอดภัยดี");
  LINE.notify("Longitude: "+String(gps.location.lng(), 6)); 
  LINE.notify("Latitude: "+String(gps.location.lat(), 6));
  LINE.notify(" CO2:  "+String (mySensor.CO2)+" ppm");
  LINE.notify(" TVOC: "+String (mySensor.TVOC)+" ppb");
  LINE.notify(" LPG: "+String (LPG_PPM) +" ppb");
  LINE.notify(" CO: "+String (ppm) +" ppm");
    }
}

แยกแบบคอมเม้นโค้ดให้เเล้วครับ

มีโค้ต 2 ชุดไม่ใช้หรือครับ

จริงๆ3ครับ ขออภัยที่ผมอธิบายไม่ครบ เเต่เมื่อกี้ผมลองเทส แบบ bluetooth กับ line notifyกับ chat bot แบบ simple แค่แสดงค่าตัวแปร ผลคือตามรูป line notifyกับchatbot ใช้ได้เเต่ พอสัพักก็reconnecไป เเต่พอ connect bluetooth เเล้วreconnectแบบยาวๆเลยครับ ผลเป็นไปตามภาพ2ครับ


#include <TridentTD_LineNotify.h>
#include <iSYNC.h>
WiFiClient client;
iSYNC iSYNC(client);
#define SSID        "Bifern_2.4G"
#define PASSWORD    "0619691096"
#define LINE_TOKEN  "RNeq6SkFENTEiQhus2ZhMo2krwP0ljw1eDeWRezLPRw"
#define LINE_TOKEN2   "ZEq8qHwUdIOVBfjF2wlAWp1Oh6AmDMC4ejky5edodTf"
#define LINE_TOKEN3  "" 

float sensor_volt;
float RS_gas; // Get value of RS in a GAS
float R0 = 15000; //example value of R0. Replace with your own
float ratio; // Get ratio RS_GAS/RS_air
float LPG_PPM;
float x=0;

String iSYNC_USERNAME = "stanutty1123";
String iSYNC_KEY = "5fb2aa195e614c07a2d8a206";
String iSYNC_AUTH = "5fb2aa015e614c07a2d8a204"; //auth project

#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;


void callback(char* topic, byte* payload, unsigned int length) {
  String msg = "";
  Serial.print("[iSYNC]-> ");
  for (int i = 0; i < length; i++){
    msg+=(char)payload[i];
    Serial.print((char)payload[i]);
  }
  Serial.println();
  if(msg.startsWith("LINE:"))msg = msg.substring(5);

  /* command control */
if(msg.equals("lpg")){
      iSYNC.mqPub(iSYNC_KEY,"Lpg :" +String (LPG_PPM) +" ppb");   //Publish
       
  }else if(msg.equals("พิกัด")){
      iSYNC.mqPub(iSYNC_KEY,"ที่นี่คือ ");
}
}
  void connectMQTT(){
  while(!iSYNC.mqConnect()){
    Serial.println("Reconnect MQTT...");
    delay(3000);
    }
  iSYNC.mqPub(iSYNC_KEY,"พร้อมรับคำสั่งแล้วจ๊ะพี่จ๋า");   //Publish on Connect
// iSYNC.mqSubProject(); //subscribe all key in your project
  iSYNC.mqSub(iSYNC_KEY); //subscribe key
  }


void setup() {
  Serial.begin(115200);
  WiFi.begin( SSID, PASSWORD );
  while(!WiFi.isConnected()) delay(400);
  Serial.println( WiFi.localIP());
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  String message = "Messeage to LINE";

  LINE.setToken(LINE_TOKEN); //LINE.notify(message);
  LINE.setToken(LINE_TOKEN2); //LINE.notify(message);
  LINE.setToken(LINE_TOKEN3); //LINE.notify(message);

//  Wire.begin();

  iSYNC.begin(SSID,PASSWORD);
  iSYNC.mqInit(iSYNC_USERNAME,iSYNC_AUTH);
  iSYNC.MQTT->setCallback(callback);
  connectMQTT();

}

void loop() {
  if (!iSYNC.mqConnected())connectMQTT();
  iSYNC.mqLoop();
   int sensorValue = analogRead(A0);
    sensor_volt=(float)sensorValue/1024*5.0;
    RS_gas = (5.0-sensor_volt)/sensor_volt;
    ratio = RS_gas/R0;
    x = 1000*ratio ;
    LPG_PPM = pow(x,-1.431);//LPG PPM

  
SerialBT.print("10");
LINE.setToken(LINE_TOKEN);
LINE.notify("10");
LINE.setToken(LINE_TOKEN2);
LINE.notify("10");
}

ทดลอง bluetooth กับ line notify พอเชื่อมต่อ bluetooth ไลน์ก็ยังเเจ้งเตือนเเต่เพียงจะขาดช่วงบ้าง แต่บูธูทเเจ้งเตือนต่อเนื่องปกติครับ

ผลดังนี้เลยครับ ขอเเนวทางวิธีการใช้ 3ตัวนี้รวมกันหน่อยครับ :cry:

1 Like

ผมว่า Root case ของกระทู้นี้น่าจะเป็นการร่วมโค้ตแล้วการทำงานมันไม่ลงตัวหรือบ้างส่วนทำงานไม่ได้ เพราะ ติดงานส่วนอื่นอยู่ ลองศึกษาจากกระทู้นี้ดูครับ คล้ายกัน แบบเป็นส่วนๆ แล้วตั้งเวลาให้มันทำงานไปพร้อมๆ กันในทีเดียว