I'm going to assume that when the App is Exited, the Data does not need to be stored. If it does need to be stored, I can show you how to store and retrieve with TinyDB.
I have to trust that your Sketch generally works, I see you have based it on code published on Git Hub (DF Robot have similar code).
However, using delay() in the main loop can adversely affect the sensor values, so I have replaced that with a time interval test instead:
SensorDataOrCmdToApp.txt (1.4 KB)
//Sensor Data or Command To App 31/01/2022 01:29:08
#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
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read(); //ESP32 internal temperature sensor
#ifdef __cplusplus
}
#endif
unsigned long lgUpdateTime;
#define BTN1 digitalRead(0)==0
#define BTN2 digitalRead(35)==0
uint8_t temprature_sens_read();
BluetoothSerial SerialBT;
void IRAM_ATTR isr() {
SerialBT.println("A");
detachInterrupt(0);
}
void IRAM_ATTR isr2() {
SerialBT.println("B");
detachInterrupt(35);
}
void setup() {
// put your setup code here, to run once:
lgUpdateTime = millis();
Serial.begin(115200);
SerialBT.begin("ESP32");
pinMode(0,INPUT);
pinMode(35,INPUT);
attachInterrupt(0, isr, FALLING);
attachInterrupt(35, isr2, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
attachInterrupt(0,isr,FALLING);
attachInterrupt(35,isr2,FALLING);
if(millis() - lgUpdateTime > 2000) //Loop approx every 2 seconds
{
lgUpdateTime = millis();
SerialBT.println((temprature_sens_read() - 32) / 1.8);
}
}