ขอความช่วยเหลือเรื่อง pulse sensor ส่งค่าแจ้งเตือนไปยัง line notify

ทำเรื่องแจ้งเตือนเมื่อ bpm สูงกว่า 120 ค่ะ pulse sensor ที่ใช้คือ MAX30100 ค่ะ upload ลง esp8266 สำเร็จ หากค่า bpm ต่ำกว่า 120 sensor ทำงานปกติหมดทุกตัวค่ะ แต่เมื่อค่า bpm สูงกว่า 120 แจ้งเตือนไลน์รับค่าที่เกิน 120 มาได้ 1 ค่าแล้วค้างค่านั้นตลอดเลยค่ะ Line Notify เด้งค่านั้นตลอด ที่ OLED ก็ค้างเช่นกันค่ะ



#include <SPI.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <ESP8266WiFi.h>
#include <TridentTD_LineNotify.h> 
#include "Wire.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define LINE_TOKEN "xxxxxxxxxx"

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define REPORTING_PERIOD_MS 1000
PulseOximeter pox;
 
TridentTD_LineNotify myLINE(LINE_TOKEN);

char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxxxx";

 float BPM, SpO2;
// Connections : SCL PIN - D1 , SDA PIN - D2 , INT PIN - D0

uint32_t tsLastReport = 0;
 
const unsigned char bitmap [] PROGMEM=
{
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x18, 0x00, 0x0f, 0xe0, 0x7f, 0x00, 0x3f, 0xf9, 0xff, 0xc0,
0x7f, 0xf9, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xf0,
0xff, 0xf7, 0xff, 0xf0, 0xff, 0xe7, 0xff, 0xf0, 0xff, 0xe7, 0xff, 0xf0, 0x7f, 0xdb, 0xff, 0xe0,
0x7f, 0x9b, 0xff, 0xe0, 0x00, 0x3b, 0xc0, 0x00, 0x3f, 0xf9, 0x9f, 0xc0, 0x3f, 0xfd, 0xbf, 0xc0,
0x1f, 0xfd, 0xbf, 0x80, 0x0f, 0xfd, 0x7f, 0x00, 0x07, 0xfe, 0x7e, 0x00, 0x03, 0xfe, 0xfc, 0x00,
0x01, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x3f, 0xc0, 0x00,
0x00, 0x0f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

//display HeartBeat
void onBeatDetected()
{
    Serial.println("Beat Detected!");
    display.drawBitmap( 60, 20, bitmap, 28, 28, 1);
    display.display();
}
 
void setup()
{
    Serial.begin(115200);

    if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
   }
    display.display();
    delay(2000);

    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(1);
    display.setCursor(0, 0);
 
    display.println("Initializing pulse oximeter..");
    display.display();
    
    pinMode(16, OUTPUT);
    delay(100);
      
    Serial.println("Connecting to ");
    Serial.println(ssid);

    //connect to your local wi-fi network
    WiFi.begin(ssid, pass);
  
      //check wi-fi is connected to wi-fi network
     while (WiFi.status() != WL_CONNECTED) {
       delay(1000);
       Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected..!");
      Serial.print("Got IP: ");  Serial.println(WiFi.localIP());
      LINE.setToken(LINE_TOKEN);

      Serial.print("Initializing Pulse Oximeter..");
 
    if (!pox.begin())
    {
         Serial.println("FAILED");
         display.clearDisplay();
         display.setTextSize(1);
         display.setTextColor(1);
         display.setCursor(0, 0);
         display.println("FAILED");
         display.display();
         for(;;);
    }
    else
    {
         display.clearDisplay();
         display.setTextSize(1);
         display.setTextColor(1);
         display.setCursor(0, 0);
         display.println("SUCCESS");
         display.display();
         Serial.println("SUCCESS");

    }
   pox.setOnBeatDetectedCallback(onBeatDetected);
    // The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
    // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
}

void loop () {

    pox.update();
    BPM = pox.getHeartRate();
    SpO2 = pox.getSpO2();

     if (millis() - tsLastReport > REPORTING_PERIOD_MS)
    {
        Serial.print("Heart rate:");
        Serial.print(BPM);
        Serial.print(" bpm / SpO2:");
        Serial.print(SpO2);
        Serial.println(" %");
        
        display.clearDisplay();
        display.setTextSize(1);
        display.setTextColor(1);
        display.setCursor(0,16);
        display.println(BPM);
 
        display.setTextSize(1);
        display.setTextColor(1);
        display.setCursor(0, 0);
        display.println("Heart BPM");
 
        display.setTextSize(1);
        display.setTextColor(1);
        display.setCursor(0, 30);
        display.println("Spo2");
 
        display.setTextSize(1);
        display.setTextColor(1);
        display.setCursor(0,45);
        display.println(SpO2);
        display.display();
 
        tsLastReport = millis();
        
        if (BPM > 120){ 
          String LineText;
          String string1 = "หัวใจเต้นเกินกำหนด ";
          String string2 = " BPM";
          LineText = string1 + BPM + string2;
          Serial.print("Line ");
          Serial.println(LineText);
          LINE.notify(LineText);
          delay(100);
          } 
     }
}

ที่ปรับให้จะเป็นการส่งไลน์แจ้งเตือนแค่ 1 ครั้ง นะครับ กรณี BPM > 120 ลองดูครับ เพราะข้อมูลมีแค่นี้

int LineNotify = 0;

void loop {

 if (BPM > 120 and LineNotify == 0 ) {
      String LineText;
      String string1 = "หัวใจเต้นเกินกำหนด ";
      String string2 = " BPM";
      LineText = string1 + BPM + string2;
      Serial.print("Line ");
      Serial.println(LineText);
      LINE.notify(LineText);
      delay(100);
      LineNotify = 1;

    }

    if (BPM < 120 and LineNotify == 1 ) {

      LineNotify = 0;

    }



}