ESP32 Bluetooth Master does not connect

I want to connect an ESP32 to a SMA Sunny Boy SB5000-TL Solar convertor over Bluetooth, but I cannot establish a connection and I'm kind of stuck.
I use the internal bluetooth module of the ESP32.

What I've done:

  • I started with this project: GitHub - delhatch/ESP32_to_SMA: ESP32 connects to SMA Sunny Boy inverter over Bluetooth but I did not get past the connection. I tried to locate the problem area:

  • I tried using an Android app (Oxley Solar) to connect to the SB5000-TL Solar convertor, and that works great. The pin code of the convertor is set to 0000.

  • I tried using two ESP32 modules, one as master, one as slave and that works as well, though I do not need to set a pin. So the bluetooth module of my ESP32 works properly.

So the problem must be in my code, I guess.

This is the code I use to connect to the convertor:

    #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;
    boolean confirmRequestPending = true;
    
    // uint8_t ESP32Slave[6]  = {0x84, 0xCC, 0xA8, 0x2C, 0x70, 0x1E}; // Address of Slave.
    uint8_t SMA[6]  = {0x00, 0x40, 0x65, 0x12, 0x4B, 0x3E}; // Address of my SMA inverter.
    const char *pin = "0000"; //<- standard pin
    
    void setup() {
      Serial.begin(115200);
      SerialBT.enableSSP();
      SerialBT.onConfirmRequest(BTConfirmRequestCallback);
      SerialBT.onAuthComplete(BTAuthCompleteCallback);
      SerialBT.begin("ESP32master", true); //Bluetooth device name
      SerialBT.register_callback(callback);
      SerialBT.setPin("0000");
      Serial.println("Connecting...");
      bool connected = SerialBT.connect(SMA);
      if (connected) {
        Serial.println("Connected!");
      } else {
        Serial.println("NOT Connected!");
      }
      delay(500);
      SerialBT.end();
      Serial.println("Bye!");
    }
    
    void loop() {
    
    }
    
    void callback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
      Serial.print("Got event!");  Serial.println(event);
    }
    
    void BTConfirmRequestCallback(uint32_t numVal)
    {
      confirmRequestPending = true;
      Serial.println(numVal);
    }
    
    void BTAuthCompleteCallback(boolean success)
    {
      confirmRequestPending = false;
      if (success)
      {
        Serial.println("Pairing success!!");
      }
      else
      {
        Serial.println("Pairing failed, rejected by user!!");
      }
    }

This is the result in the Serial console:

    Connecting...
    Got event!0
    Got event!8
    NOT Connected!
    Got event!1
    Bye!

I tried to replace the Mac Address with the name of the Convertor,
I tried with and without pin.

I'm kind of stuck.
Any idea's of how I can check what is wrong?

Any advice would be greatly appreciated!

Hallo mvermand,
Ik jouw code getest, uiteraard het mac adress aangepast en de inlogcode en ik krijg de volgende output.
Got event!0
Connecting...
Got event!8
Got event!29
Pairing success!!
Connected!
Got event!26
Got event!30
Got event!27
Got event!1
Bye!

kijk jouw macadress nog eens na.
bduist

Sorry I replied in dutch .
I tested your code with the following result :

Got event!0
Connecting...
Got event!8
Got event!29
Pairing success!!
Connected!
Got event!26
Got event!30
Got event!27
Got event!1
Bye!

Check your mac adress.