Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BluetoothSerial.h"
- BluetoothSerial SerialBT;
- const char* realDeviceName = "EMUCANBT_SPP"; // Replace with actual Bluetooth device name
- //uint8_t canDeviceMAC[] =
- void setup() {
- Serial.begin(115200);
- SerialBT.begin("ESP32-CYD", true); // True = ESP32 as a client
- //SerialBT.setPin("1234");
- Serial.println("Attempting to connect to real device...");
- if (SerialBT.connect(realDeviceName)) {
- Serial.println("Connected successfully!");
- } else {
- Serial.println("Connection failed. Retrying...");
- }
- }
- void loop() {
- if (SerialBT.connected()) {
- if (SerialBT.available()) {
- Serial.print("Received: ");
- Serial.write(SerialBT.read());
- }
- } else {
- Serial.println("Disconnected. Attempting reconnect...");
- SerialBT.connect(realDeviceName);
- delay(5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment