Reputation: 1
Making an app right now that interacts with an ESP32 through bluetooth classic. I'm reading the hall sensor and sending a 0 when its value is above 0, and a 1 when below. Now, when I register that 1 in ai2 and some things happen in the app because of it, the ESP32 malfunctions or something. I stop getting readings from the sensor in the serial monitor, and the bluetooth connection stops. It just seems like the whole esp just stops dead in its tracks. I'm also not sending any data to the ESP32, just receiving from it. The esp code is super small, but the app code not so much. Only way to fix this issue is resetting the esp, which isn't really doable in my usecase. Any way to fix this?
#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 setup() {
Serial.begin(115200);
SerialBT.begin("Sport Spel"); //Bluetooth device name
}
void loop() {
Serial.println(hallRead());
if (SerialBT.available)
{
if (hallRead() < 0)
{
SerialBT.write('1');
}
else
{
SerialBT.write('0');
}
delay(20);
}
}
Upvotes: 0
Views: 337
Reputation: 7109
The line
if (SerialBT.available)
should be
if (SerialBT.available())
As it's written in your question, you're testing whether the address of the method named available
on the SerialBT
object is true, which it always will be. You want to actually call that method, so you need to include the parentheses in order to invoke it.
Upvotes: 1