Error 507:unable to connect.is device turn on?

hello i have problem with my mit app where the bluetooth is cannot connect to my esp32..it say error 507:unable to connect.is device turn on?here is the bluetooth part and my mit file...before this it working but now it suddenly not working ...please help me...what wrong with mit code block :sob:

FWAS_Transmitter (1).aia (102.9 KB)

I opened your project, did a Cleanup Blocks, and used the Ctrl-F search facility to do a grand tour of blocks containing the word BlueTooth.

Here are some fishy things I found:


If you were just granted this permission, why would you then immediately ask for that permission again? Maybe this was intended for asking for two different permissions, one at a time?


You check BlueTooth Enabled immediately after requesting permission(s), without allowing for the time it might take for enablement to happen. This test probably needs to happen later, after permissions have been dealt with?
And why does the error message mention connection, when it is issued after testing enablement? Aren't those two different things?
Enabled means ready and willing to connect,
Connected means actually found something to connect to, and connected to it.


Zoom in on the top, where you try to get a stream of bytes:
image

You test for at least 1 byte of data available in the buffer.
Then you ask for a bunch of bytes, one at a time.
Asking for a byte that isn't yet there locks up the app until one arrives.
If you are sending bunches of bytes, it would be good to know how many bytes per bunch and ask for all the bytes at once on a list.

This is a good time to learn how to work with lists.
Read a starter article in

P.S. Maybe also post your sketch, so we can see what's in all those bytes?

Testing2.ino (28.5 KB)
this is my sketch

For the hardware mavens on this board reading this thread on your phone, here's your sketch inline:

Summary

#include <WiFi.h>
#include <WiFiMulti.h>
#include <WiFiClientSecure.h>
#include "EEPROM.h"
#include "BluetoothSerial.h"

#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif

#define EEPROM_SIZE 64

#define sirenPin 32
#define redPin 33
#define yellowPin 25
#define fanPin 26

// internal temp
#ifdef __cplusplus
extern "C" {
#endif
  uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
//-------

//Bluetooth
String device_name = "ESP32-BT";

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

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;
//----------------------------------



WiFiMulti wifiMulti;

const char *host = "script.google.com";
//Spreadsheet script ID
String SCRIPT_ID = "AKfycbySEzQApEul18-cAI5-vMOrqbM4l8qOOgGEbWOXHfkO6F3Jvq-W77uQcdipulEOB7m0";
const int httpsPort = 443;

WiFiClientSecure client;

// Define tree tasks
void Task01(void *pvParameters);
void Task02(void *pvParameters);
void Task03(void *pvParameters);

//ultrasonic
#define echoPin 5
#define trigPin 18

int IDDevice = 0;  //--------------------------------------------------------ID HERE
const int ledBoard = 2;
//#define voltageSensingPin 27

// defines variables
//int codeVersion = 6;  //    <<<<<< for major update mcm tambah eeprom library
int codeVersion = 7;

int tempIntFix = 0;
//history==> 0= original, 1= tambah penggunaan location epprom, 2= location epprom history, 3= internal heat sensor, 4= warning red and yellow lamp, 5=Perluasan sensor, 6=IoT spreadsheet
long duration;
byte dataread, data2read;
int countEeprom = 199, timingCountEeprom = 180, dataToEeprom;  //3 minit = 180sec
int FirstApproveCode, SecondApproveCode = 103, IDDeviceTemp = 0;
int distance, distanceControl, constrainError, tempInternal, tempActivation = 28, fanDelay = 4, constrainPeak = 1, constrainGap = 1, eepromread, fanControl = 0, firstWarningLight = 0, secondWarningLight = 0, alarmSound = 0, alarmTimingOff = 0, alarmTimingOffSecToMin = 0, statisticCycleLimit = 0, statisticSend, statisticJob = 0, distanceControlReset, distanceC[11], ResetZeroPoint;
int countstart = 0, warningLVL, yellowLVL, redLVL, pointHourSave[8], flipBT = 0;
int ledPulse = 0, ledPulse2 = 0, distanceEdit, distanceControlEdit, disCDifference, disC01 = 0, disC02 = 0, LastConstrainChange = 0;

int lifePulse = 1, indicatorAcc = 10;
int caa = 1, cbb = 1, ccc = 0, cdd = 0, cee = 0, cff = 0, cgg = 0, chh = 0, cii = 0, cjj = 0, ckk = 0;  //a,b are variables to store sensor values


float R1 = 30000.0, R2 = 7500.0, vKeluar = 0.0, voltageSensor = 120.0;
int voltageSensingGet = 0;
int wifiRestartTimer = (60 * 3), wifiTimer = 10, SerialSwitchListen = 0;  //in saat >> for minit = 60*29

int eepromAread01, eepromAread02;
int dcount = 0, BluetoothToWifiCountDown = 30, OnBluetooth = 0;

int DisconnectWifiClient = 0, dalamMinit = 15, dalamMinitSet = 12, switchProcess = 0, TimerProcess = 6, TimerProcessRun = 2, HoldProcess = 0;

void setup() {
  Serial.begin(115200);
  delay(500);
  EEPROM.begin(EEPROM_SIZE);
  delay(200);

  SerialBT.begin(device_name);  //Bluetooth device name

  pinMode(ledBoard, OUTPUT);  //ledBoard

  pinMode(trigPin, OUTPUT);  // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT);   // Sets the echoPin as an INPUT

  //output

  pinMode(sirenPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(fanPin, OUTPUT);

  digitalWrite(sirenPin, LOW);
  digitalWrite(redPin, LOW);
  digitalWrite(yellowPin, LOW);
  digitalWrite(fanPin, LOW);

  //pinMode(voltageSensingPin, INPUT);//voltage sensing

  digitalWrite(ledBoard, HIGH);

  //SETUP WIFI CONNECTION
  WiFi.mode(WIFI_STA);

  wifiMulti.addAP("Wifi1", "Pass1");  //edit Wifi and pass to add access wifi
  //wifiMulti.addAP("Wifi2", "Pass2");
  //wifiMulti.addAP("Wifi3", "Pass3");
  //wifiMulti.addAP("Wifi4", "Pass4");
  //wifiMulti.addAP("Wifi5", "Pass5");

  //>>-Serial.println("Connecting Wifi...");
  if (wifiMulti.run() == WL_CONNECTED) {
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    delay(200);
    //digitalWrite(ledBoard, HIGH);
    delay(300);
    //digitalWrite(ledBoard, LOW);
    //>>-Serial.print(".");
  }
  delay(2000);

  xTaskCreatePinnedToCore(
    Task01, "Task 01"  // A name just for humans
    ,
    3072  //1024        // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
    ,
    NULL  // Task parameter which can modify the task behavior. This must be passed as pointer to void.
    ,
    1  // Priority
    ,
    NULL  // Task handle is not used here - simply pass NULL
    ,
    1  //core run
  );

  xTaskCreatePinnedToCore(
    Task02, "Task 02"  // A name just for humans
    ,
    3072  // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
    ,
    NULL  // Task parameter which can modify the task behavior. This must be passed as pointer to void.
    ,
    2  // Priority
    ,
    NULL  // Task handle is not used here - simply pass NULL
    ,
    1  //core run
  );

  xTaskCreatePinnedToCore(
    Task03, "Task 03"  // A name just for humans
    ,
    29696  // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
    ,
    NULL  // Task parameter which can modify the task behavior. This must be passed as pointer to void.
    ,
    3  // Priority
    ,
    NULL  // Task handle is not used here - simply pass NULL
    ,
    0  //core run - Wifi fokus
  );

  eepromAread01 = byte(EEPROM.read(0));
  eepromAread02 = byte(EEPROM.read(2));
  Serial.println(eepromAread01);
  Serial.println(eepromAread02);
  //eeprom setup
  //if (eepromAread01 == 102 && eepromAread02 == codeVersion) {
  if (eepromAread01 == 103 && eepromAread02 == codeVersion) {
    FirstApproveCode = byte(EEPROM.read(0));
    ResetZeroPoint = (EEPROM.read(1)) + (EEPROM.read(15));
    warningLVL = byte(EEPROM.read(3));
    tempActivation = byte(EEPROM.read(12));
    redLVL = byte(EEPROM.read(13));
    yellowLVL = byte(EEPROM.read(14));

    IDDevice = (byte(EEPROM.read(16)) * 100) + byte(EEPROM.read(17));
    Serial.println("EEPROM Read");
  } else {
    EEPROM.write(2, codeVersion);  //version update
    //EEPROM.write(0, 102);
    EEPROM.write(0, 103);
    EEPROM.write(1, 80);         //zero range sensor
    EEPROM.write(15, 99);        //zero range sensor
    EEPROM.write(3, 50);         //warning level
    EEPROM.write(13, 45);        //red level
    EEPROM.write(14, 40);        //yellow level
    EEPROM.write(16, 0);         //data id dpn
    EEPROM.write(17, IDDevice);  //data id

    EEPROM.write(12, 28);  //fan

    EEPROM.commit();  //commit save

    FirstApproveCode = byte(EEPROM.read(0));
    ResetZeroPoint = (EEPROM.read(1)) + (EEPROM.read(15));
    warningLVL = byte(EEPROM.read(3));
    redLVL = byte(EEPROM.read(13));
    yellowLVL = byte(EEPROM.read(14));

    IDDevice = (byte(EEPROM.read(16) * 100)) + byte(EEPROM.read(17));
    Serial.println("EEPROM Write");
  }

  //  for (int i = 0; i < EEPROM_SIZE; i++)
  //  {
  //    Serial.print(i); Serial.print(" "); Serial.print( byte(EEPROM.read(i))); Serial.println(" ");
  //  }
  //  Serial.println();
  //
  digitalWrite(ledBoard, LOW);
}

void loop() {
  //delay(10000); // While not being used yield the CPU to other tasks
}

void Task01(void *pvParameters) {  // This is a task.
  for (;;) {
    if (TimerProcessRun <= 0) {
      /*if (ledPulse==0)
      {
        delay(200);
        //voltage sensor
        voltageSensingGet = analogRead(voltageSensingPin);
        //vKeluar = (voltageSensingGet*3.3)/4095.0;
        //voltageSensor = (vKeluar / (R2/(R1+R2)));
        voltageSensor = float(map(voltageSensingGet, 0, 1123, 0, 506))/100;
      
        Serial.print(voltageSensingGet);
        Serial.print("  ");
        Serial.println(voltageSensor);
        delay(200);
        //------
        ledPulse=1;
      }
      else
      {*/
      delay(1000);
      // internal temp
      Serial.print("Temperature: ");
      tempInternal = int((temprature_sens_read() - 32) / 1.8);
      Serial.print(tempInternal);
      Serial.println(" C");
      //------
      //ledPulse=0;
      delay(1000);
      //}
      TimerProcessRun = TimerProcess;
    } else {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      // Reads the echoPin, returns the sound wave travel time in microseconds
      duration = pulseIn(echoPin, HIGH);
      // Calculating the distance
      distance = (duration * 0.0343) / 2;  // Speed of sound wave divided by 2 (go and back)

      if (distance >= 350) {
        distance = 350;
      }
    }


    if (countstart <= 2) {
    } else {
    }

    distanceC[10] = distanceC[9];
    distanceC[9] = distanceC[8];
    distanceC[8] = distanceC[7];
    distanceC[7] = distanceC[6];
    distanceC[6] = distanceC[5];
    distanceC[5] = distanceC[4];
    distanceC[4] = distanceC[3];
    distanceC[3] = distanceC[2];
    distanceC[2] = distanceC[1];
    distanceC[1] = distanceC[0];
    distanceC[0] = distance;


    //from loop -- for Bluetooth
    if (SerialBT.available() > 0) {
      dataread = SerialBT.read();

      if (dataread == 1)  //reset position
      {
        ResetZeroPoint = map(distanceControl, 0, 400, 400, 0);
        countstart = 0;
      } else if (dataread == 2)  //addsetlvl
      {
        if (warningLVL <= 199) {
          warningLVL++;
        }
      } else if (dataread == 3)  //subsetlvl
      {
        if (warningLVL >= 5) {
          warningLVL--;
        }
      } else if (dataread == 4)  //addsetlvl5
      {
        if (warningLVL <= 194) {
          warningLVL = warningLVL + 5;
        }
      } else if (dataread == 5)  //subsetlvl5
      {
        if (warningLVL >= 11) {
          warningLVL = warningLVL - 5;
        }
      } else if (dataread == 6)  //SaveSetting
      {
        Serial.println(ResetZeroPoint);
        EEPROM.write(3, warningLVL);  //warning level
        EEPROM.write(1, ResetZeroPoint / 2);
        EEPROM.write(15, ResetZeroPoint / 2);
        EEPROM.write(12, tempActivation);  //fan
        EEPROM.write(13, redLVL);          //red level
        EEPROM.write(14, yellowLVL);       //yellow level
        IDDeviceTemp = IDDevice / 100;
        EEPROM.write(16, IDDeviceTemp);                     //IDdepan
        EEPROM.write(17, IDDevice - (IDDeviceTemp * 100));  //IDbelakang


        EEPROM.commit();         //commit save
      } else if (dataread == 7)  //OpenStatistic
      {
        statisticJob = 2;
      } else if (dataread == 8)  //CloseStatistic
      {
        statisticJob = 0;
      } else if (dataread == 9)  //FanAdd
      {
        if (tempActivation <= 89) {
          tempActivation++;
        }
      } else if (dataread == 10)  //FanSub
      {
        if (tempActivation >= 2) {
          tempActivation--;
        }
      } else if (dataread == 11)  //SirenWarningOff
      {
        if (alarmTimingOff <= 60) {
          alarmTimingOff = 62;
        } else if (alarmTimingOff >= 61) {
          alarmTimingOff = 0;
        }
      } else if (dataread == 12)  //addredLVL
      {
        if (redLVL <= 199) {
          redLVL++;
        }
      } else if (dataread == 13)  //subredLVL
      {
        if (redLVL >= 4) {
          redLVL--;
        }
      } else if (dataread == 14)  //addredLVL5
      {
        if (redLVL <= 194) {
          redLVL = redLVL + 5;
        }
      } else if (dataread == 15)  //subredLVL5
      {
        if (redLVL >= 11) {
          redLVL = redLVL - 5;
        }
      } else if (dataread == 16)  //addyellowLVL
      {
        if (yellowLVL <= 199) {
          yellowLVL++;
        }
      } else if (dataread == 17)  //subyellowLVL
      {
        if (yellowLVL >= 3) {
          yellowLVL--;
        }
      } else if (dataread == 18)  //addyellowLVL5
      {
        if (yellowLVL <= 194) {
          yellowLVL = yellowLVL + 5;
        }
      } else if (dataread == 19)  //subyellowLVL5
      {
        if (yellowLVL >= 11) {
          yellowLVL = yellowLVL - 5;
        }
      } else if (dataread == 20)  //IDadd100
      {
        if (IDDevice <= 9899) {
          IDDevice = IDDevice + 100;
        }
      } else if (dataread == 21)  //IDadd5
      {
        if (IDDevice <= 9994) {
          IDDevice = IDDevice + 5;
        }
      } else if (dataread == 22)  //IDadd
      {
        if (IDDevice <= 9998) {
          IDDevice++;
        }
      } else if (dataread == 23)  //IDsub
      {
        if (IDDevice >= 1) {
          IDDevice--;
        }
      } else if (dataread == 24)  //IDsub5
      {
        if (IDDevice >= 6) {
          IDDevice = IDDevice - 5;
        }
      } else if (dataread == 25)  //ID to zero
      {
        if (IDDevice >= 1) {
          IDDevice = 0;
        }
      } else if (dataread == 50)  //wifi reset
      {

      } else if (dataread == 30)  //request saat
      {
        if (BluetoothToWifiCountDown >= 1) {
          OnBluetooth = 1;                //bluetooth send
          BluetoothToWifiCountDown = 30;  //reset wifi countdown
        }
      }

      dataread = 0;
    }

    //end loop

    dcount++;
    //Serial.print(dcount);
    delay(100);
    //int uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
    //Serial.println(uxHighWaterMark);
  }
}

void Task02(void *pvParameters) {  // This is a task.
  for (;;) {
    //Serial.println(" 1 Saat ---------------- >");
    distanceControl = (distanceC[0] + distanceC[1] + distanceC[2] + distanceC[3] + distanceC[4] + distanceC[5] + distanceC[6] + distanceC[7] + distanceC[8] + distanceC[9]) / 10;

    constrainError = distanceControl;
    distanceControlEdit = (map(distanceControl, 0, 400, 240, 0)) - ResetZeroPoint;

    disC02 = disC01;
    disC01 = distanceControlEdit;
    disCDifference = disC01 - disC02;

    if (countstart <= 2) {
      countstart++;
    }

    if (BluetoothToWifiCountDown >= 1) {
      BluetoothToWifiCountDown--;
      Serial.print("Cdown  ");
      Serial.println(BluetoothToWifiCountDown);
    } else {
    }

    if (BluetoothToWifiCountDown == 72)  //active bluetooth time
    {
      //OnBluetooth=1;
    }

    if (BluetoothToWifiCountDown == 7)  //diactivated bluetooth and close
    {
      //OnBluetooth=0;
      SerialBT.flush();
      SerialBT.disconnect();
      SerialBT.end();  //perlu sebab nnti fungsi wifi x function dan error
      delay(1000);
      //btStop();
    }
    if (BluetoothToWifiCountDown == 2)  //active wifi
    {
      //setupWifi();
    }

    //BT Serial send

    if (OnBluetooth == 1) {
      SerialBT.flush();
      delay(200);
      SerialBT.write(FirstApproveCode);  //first approve code ---- 1 no mapping
      if (distanceControlEdit >= 201) {
        SerialBT.write(100);  //level water
        SerialBT.write(100);  //level water
      } else if (distanceControlEdit >= 100 && distanceControlEdit <= 200) {
        SerialBT.write(99);                        //level water
        SerialBT.write(distanceControlEdit - 99);  //level water
      } else if (distanceControlEdit >= -100 && distanceControlEdit <= 99) {
        SerialBT.write(distanceControlEdit - 1);  //level water
        SerialBT.write(1);                        //level water
      } else {
        SerialBT.write(-102);  //level water
        SerialBT.write(1);     //level water
      }
    }


    if (countstart <= 2) {
      if (OnBluetooth == 1) {
        SerialBT.write(1);
        SerialBT.write(10);
      }
    } else {
      if (OnBluetooth == 1) {
        SerialBT.write(disCDifference);  //Acceleration
      }

      if (distanceControlEdit >= yellowLVL && distanceControlEdit >= redLVL && distanceControlEdit >= warningLVL) {
        //Serial.println(" !!!! Warning Level");//indicator display
        alarmSound = 1;
        secondWarningLight = 1;
        firstWarningLight = 1;
        if (OnBluetooth == 1) {
          SerialBT.write(11);
        }
      } else {
        if (distanceControlEdit >= warningLVL) {
          alarmSound = 1;
        } else {
          alarmSound = 0;
        }

        if (distanceControlEdit >= redLVL) {
          secondWarningLight = 1;
        } else {
          secondWarningLight = 0;
        }

        //bypass redLVL and Alarm
        if (disCDifference >= 9)  //("sub function >>>> Increase Danger Fast");
        {
          //alarmSound=1;
          secondWarningLight = 1;  //red
        }


        if (distanceControlEdit >= yellowLVL) {
          firstWarningLight = 1;
        } else {
          firstWarningLight = 0;
        }

        //indicator only--------------------------------------------------------
        if (disCDifference <= -7) {
          //Serial.println(" <<<- Decrease Extream Fast");
          indicatorAcc = -3;
        } else if (disCDifference >= -6 && disCDifference <= -5) {
          //Serial.println(" <<-- Decrease Fast");
          indicatorAcc = -2;
        } else if (disCDifference >= -4 && disCDifference <= -2) {
          //Serial.println(" <--- Decrease");
          indicatorAcc = -1;
        } else if (disCDifference >= -1 && disCDifference <= 1) {
          //Serial.println(" --|-- Normal");
          indicatorAcc = 10;
        } else if (disCDifference >= 2 && disCDifference <= 4) {
          //Serial.println(" >--- Increase");
          indicatorAcc = 1;
        } else if (disCDifference >= 5 && disCDifference <= 6) {
          //Serial.println(" >>-- Increase Fast");
          indicatorAcc = 2;
        } else if (disCDifference >= 7 && disCDifference <= 8) {
          //Serial.println(" >>>- Increase Extream Fast");
          indicatorAcc = 3;
        } else if (disCDifference >= 9) {
          //Serial.println(" >>>> Increase Danger Fast");
          indicatorAcc = 4;
        }
        if (OnBluetooth == 1) {
          SerialBT.write(indicatorAcc);
        }
      }
    }

    if (OnBluetooth == 1) {
      //warning level
      if (warningLVL >= 201) {
        SerialBT.write(100);  //level water
        SerialBT.write(100);  //level water
      } else if (warningLVL >= 100 && warningLVL <= 200) {
        SerialBT.write(99);               //level water
        SerialBT.write(warningLVL - 99);  //level water
      } else if (warningLVL >= -100 && warningLVL <= 99) {
        SerialBT.write(warningLVL - 1);  //level water
        SerialBT.write(1);               //level water
      } else {
        SerialBT.write(-102);  //level water
        SerialBT.write(1);     //level water
      }
    }


    if (OnBluetooth == 1) {
      SerialBT.write(tempInternal + tempIntFix);
    }

    if (tempInternal >= tempActivation) {
      fanDelay = 5;
    }

    if (fanDelay >= 1) {
      fanDelay--;
      //digitalWrite(4, HIGH);//low == on fanPin
      digitalWrite(fanPin, HIGH);  //low == on
      if (OnBluetooth == 1) {
        SerialBT.write(2);
      }
    } else {
      //digitalWrite(4, LOW);//high == off
      digitalWrite(fanPin, LOW);  //high == off
      if (OnBluetooth == 1) {
        SerialBT.write(1);
      }
    }
    if (OnBluetooth == 1) {
      SerialBT.write(tempActivation + tempIntFix);
    }

    if (OnBluetooth == 1) {
      //redLVL
      if (redLVL >= 201) {
        SerialBT.write(100);  //level water
        SerialBT.write(100);  //level water
      } else if (redLVL >= 100 && redLVL <= 200) {
        SerialBT.write(99);           //level water
        SerialBT.write(redLVL - 99);  //level water
      } else if (redLVL >= -100 && redLVL <= 99) {
        SerialBT.write(redLVL - 1);  //level water
        SerialBT.write(1);           //level water
      } else {
        SerialBT.write(-102);  //level water
        SerialBT.write(1);     //level water
      }

      //yellowLVL
      if (yellowLVL >= 201) {
        SerialBT.write(100);  //level water
        SerialBT.write(100);  //level water
      } else if (yellowLVL >= 100 && yellowLVL <= 200) {
        SerialBT.write(99);              //level water
        SerialBT.write(yellowLVL - 99);  //level water
      } else if (yellowLVL >= -100 && yellowLVL <= 99) {
        SerialBT.write(yellowLVL - 1);  //level water
        SerialBT.write(1);              //level water
      } else {
        SerialBT.write(-102);  //level water
        SerialBT.write(1);     //level water
      }

      IDDeviceTemp = IDDevice / 100;
      SerialBT.write(IDDeviceTemp);                     //iddpn
      SerialBT.write(IDDevice - (IDDeviceTemp * 100));  //id
    }

    if (ledPulse == 0) {
      if (ledPulse2 == 0) {
        ledPulse2 = 1;
      } else {
        ledPulse2 = 0;
      }
    }
    //Pulse 1 2 1 2 for indication status
    if (OnBluetooth == 1) {
      if (ledPulse2 == 0) {
        SerialBT.write(1);
      } else {
        SerialBT.write(2);
      }

      //voltage sensor
      SerialBT.write(voltageSensor);

      OnBluetooth = 0;  //for final
    }

    //end data send
    Serial.print("yellowLVL= ");
    Serial.print(yellowLVL);
    Serial.print("  ");
    Serial.print("redLVL= ");
    Serial.print(redLVL);
    Serial.print("  ");
    Serial.print("warningLVL= ");
    Serial.println(warningLVL);
    Serial.print("tempInternal= ");
    Serial.print(tempInternal);
    Serial.print("  ");
    Serial.print("tempActivation= ");
    Serial.print(tempActivation);
    Serial.print("  ");
    Serial.print("alarmSound= ");
    Serial.println(alarmSound);

    Serial.print("distanceControl= ");
    Serial.print(distanceControl);
    Serial.print("  ");
    Serial.print("distanceControlEdit= ");
    Serial.print(distanceControlEdit);
    Serial.print("  ");
    Serial.print("ResetZeroPoint= ");
    Serial.print(ResetZeroPoint);  //ResetZeroPoint
    Serial.print("  ");
    Serial.print("constrainGap= ");
    Serial.println(constrainGap);

    //gap control  --distanceControl  --constrainGap

    LastConstrainChange = disCDifference;

    //alarmSound=0;
    //secondWarningLight=0;
    //firstWarningLight=0;

    //    pinMode(sirenPin, OUTPUT);
    //    pinMode(redPin, OUTPUT);
    //    pinMode(yellowPin, OUTPUT);
    //    pinMode(fanPin, OUTPUT);

    alarmTimingOffSecToMin++;
    if (alarmTimingOffSecToMin >= 60) {
      if (alarmTimingOff <= 60) {
        alarmTimingOff++;
      }
      alarmTimingOffSecToMin = 0;
    }

    if (alarmSound == 1) {
      digitalWrite(sirenPin, HIGH);
      /*if (alarmTimingOff <= 14)  //----- 15 minit
      {
        digitalWrite(sirenPin, HIGH);  //low == on
      } else if (alarmTimingOff == 15) {
        digitalWrite(sirenPin, LOW);  //high == off
      } else if (alarmTimingOff == 20) {
        digitalWrite(sirenPin, HIGH);  //low == on
      } else if (alarmTimingOff == 23) {
        digitalWrite(sirenPin, LOW);  //high == off
      } else if (alarmTimingOff == 30) {
        digitalWrite(sirenPin, HIGH);  //low == on
      } else if (alarmTimingOff == 33) {
        digitalWrite(sirenPin, LOW);  //high == off
      } else if (alarmTimingOff == 40) {
        digitalWrite(sirenPin, HIGH);  //low == on
      } else if (alarmTimingOff == 43) {
        digitalWrite(sirenPin, LOW);  //high == off
      } else if (alarmTimingOff == 50) {
        digitalWrite(sirenPin, HIGH);  //low == on
      } else if (alarmTimingOff == 53) {
        digitalWrite(sirenPin, LOW);  //high == off
      } else if (alarmTimingOff >= 60) {
        alarmTimingOff = 62;
        digitalWrite(sirenPin, LOW);  //high == off
      }*/
    } else {
      alarmTimingOff = 0;
      alarmTimingOffSecToMin = 0;
      digitalWrite(sirenPin, LOW);  //high == off
    }

    if (secondWarningLight == 1) {
      digitalWrite(redPin, HIGH);  //ON
    } else {
      digitalWrite(redPin, LOW);  //OFF
    }
    if (firstWarningLight == 1) {
      digitalWrite(yellowPin, HIGH);  //ON
    } else {
      digitalWrite(yellowPin, LOW);  //OFF
    }

    //    //wifi control auto timer reset
    //    wifiTimer--;
    //    if (wifiTimer==4)
    //    {
    //      digitalWrite(12, LOW);
    //    }
    //    if (wifiTimer<=0)
    //    {
    //      digitalWrite(12, HIGH);
    //      wifiTimer=wifiRestartTimer;
    //    }
    //    //Serial.println(wifiTimer);

    dcount = 0;
    delay(1000);
    //int uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
    //Serial.println(uxHighWaterMark);
  }
}

void Task03(void *pvParameters) {  //wifi fokus
                                   // This is a task.
  for (;;) {
    //lifePulse 0 1 0 1
    if (lifePulse == 1) {
      //digitalWrite(ledBoard, HIGH);
      lifePulse = 2;
    } else {
      lifePulse = 1;
      //digitalWrite(ledBoard, LOW);
    }

    if (TimerProcessRun >= 1) {
      TimerProcessRun--;
    }

    dalamMinit--;


    caa = IDDevice;  //id
    if (dalamMinit <= 0) {
      Serial.println("Cloud Send 1 minit");
      cbb = 3;  //lifePulse
      dalamMinit = dalamMinitSet;
    } else {
      cbb = lifePulse;  //lifePulse
      Serial.println("Cloud Send 5 sec");
    }
    ccc = distanceControlEdit;  //waterLVL
    cdd = disCDifference;       //acceration
    cee = indicatorAcc;         //indicator
    cff = warningLVL;           //warningLVL
    cgg = redLVL;               //redLVL
    chh = yellowLVL;            //yellowLVL
    cii = tempInternal;         //heatNow
    cjj = 120;                  //voltageSensor
    ckk = tempActivation;       //heatSet

    if (countstart <= 2) {
    } else {
      if (BluetoothToWifiCountDown <= 1)  //active wifi
      {
        if (wifiMulti.run() == WL_CONNECTED) {
          Serial.println("");
          Serial.println("WiFi connected");
          Serial.println("IP address: ");
          Serial.println(WiFi.localIP());
        }
        sendCloudData(caa, cbb, ccc, cdd, cee, cff, cgg, chh, cii, cjj, ckk);  //This function uploads data to Google Sheets
      }
    }

    delay(5000);
    //    int uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
    //    Serial.println(uxHighWaterMark);
  }
}

void sendCloudData(int caa, int cbb, int ccc, int cdd, int cee, int cff, int cgg, int chh, int cii, int cjj, int ckk) {
  if (wifiMulti.run() != WL_CONNECTED) {
    //>>-Serial.println("WiFi not connected!");
    DisconnectWifiClient++;
    if (dalamMinit <= 2) {
      dalamMinit = 2;
    }
    if (DisconnectWifiClient >= 9) {
      ESP.restart();
    }
    //delay(1000);
  } else {
    client.setInsecure();
    digitalWrite(ledBoard, HIGH);
    //>>-Serial.print("Connecting to ");
    //>>-Serial.println(host);

    if (!client.connect(host, httpsPort)) {  // HTTPS Connection pada Port
      //>>-Serial.println("Connection failed");
      DisconnectWifiClient++;
      if (dalamMinit <= 2) {
        dalamMinit = 2;
      }
      if (DisconnectWifiClient >= 9) {
        ESP.restart();
      }
      return;  //Stop Process jika connection failed
    } else {   //in connection
      DisconnectWifiClient = 0;

      //IDDevice
      String aa = String(caa);
      String bb = String(cbb);
      String cc = String(ccc);
      String dd = String(cdd);
      String ee = String(cee);
      String ff = String(cff);
      String gg = String(cgg);
      String hh = String(chh);
      String ii = String(cii);
      String jj = String(cjj);
      String kk = String(ckk);
      String url = "https://script.google.com/macros/s/" + SCRIPT_ID + "/exec?val0=" + aa + "&val1=" + bb + "&val2=" + cc + "&val3=" + dd + "&val4=" + ee + "&val5=" + ff + "&val6=" + gg + "&val7=" + hh + "&val8=" + ii + "&val9=" + jj + "&val10=" + kk;
      //>>-Serial.print("Requesting URL: ");
      //>>-Serial.println(url);

      client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: BuildFailureESP32\r\n" + "Connection: close\r\n\r\n");

      //>>-Serial.println("Request sent");

      digitalWrite(ledBoard, LOW);

      client.stop();  //DISCONNECT HTTPS Connection
    }
  }
}

This scheme is a three ring circus, coordinating Google Scripts that are triggered from the sketch, BlueTooth traffic between the sketch and the app, and an app that talks BlueTooth to the sketch and deals with the Google Sheet.

I'm not a sketch expert.
But I notice your sketch is different from others I've seen in its event loops.

Usually I see a simple void loop with delays or clock checking, handling input and output.

Your sketch, however, has an empty void loop(), supplemented by what appear to be specially named Task01, Task02,... procedures.

This a complex juggling act.
Where did you get all this?

Things that can stop working on their own:

  • You copied something wrong. Compare your code against the original.
  • Google got tired of running your scripts too frequently
  • Your app lost some Bluetooth permissions needed for connection, when Android made its rounds of turning off permissions for safety.
  • Your WiFi network changed, and the sketch decided to not connect.
  • WiFi and BlueTooth share the same radio band. How's your local RF traffic lately?

Aside from my earlier observations, which still need to addressed, I'm stumped.

i get this from my lecturer .this is for my project. i need to enhanced this mit by add 2 features that is battery status and camera live streaming...this project already working but it suddenly not working even though it was okay before.

tq for your help and advice i will try to look up for your suggestion