Reputation: 21
I want to set an ESP32 microcontroller as master and make him connect to a HC-05 bt module. I am using the examples SerialToSerialBTM.ino of the Arduino IDE,but if put the MAC address of the Bluetooth Module it print "connected successfully" in the Serial Monitor and then it print this error and the ESP32 reset itself and restart.
Stack smashing protect failure!
abort() was called at PC 0x400d5ee8 on core 0
Backtrace: 0x4009194c:0x3ffcfb30 0x40091b7d:0x3ffcfb50 0x400d5ee8:0x3ffcfb70 0x400fe443:0x3ffcfb90 0x400f58d2:0x3ffcfbe0 0x4008e0bd:0x3ffcfc10
If I put a casual MAC address it always print "connected succesfully",but it doesn't restart. The code that I use in the Arduino IDE is this, can anyone tell me more about this error and how can I make my code work?
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
String MACadd = "98:D3:32:11:31:37";
uint8_t address[6] = {0x98, 0xD3, 0x32, 0x11, 0x31, 0x37};
//uint8_t address[6] = {0x11, 0x1D, 0xA5, 0x02, 0xC3, 0x22};
String name = "HC-05";
char *pin = "1234"; //<- standard pin would be provided by default
bool connected;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test", true);
SerialBT.setPin(pin);
Serial.println("The device started in master mode, make sure remote BT device is on!");
connected = SerialBT.connect(address);
if(connected) {
Serial.println("Connected Succesfully!");
} else {
while(!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
}
}
// disconnect() may take upto 10 secs max
if (SerialBT.disconnect()) {
Serial.println("Disconnected Succesfully!");
}
// this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
SerialBT.connect();
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}
Upvotes: 2
Views: 4620
Reputation: 1
instead of
connected = SerialBT.connect(address)
try like this
connected = SerialBT.connect(name)
Upvotes: 0