schoolpost/BlueMagic32

M5Stick/Esp32 does not reconnect to BMPCC 4k after power cycling either of them.

Opened this issue · 2 comments

The M5Stick pairs without a problem with the camera(BMPCC 4k) but after power cycling them ( turning the camera or the M5Stick off and on again), they do not reconnect. Sometimes, the M5Stack says connection successful and the camera says connection failed, other times nothing happens at all.

This is my code:


#include <BlueMagic32.h>
#include <M5StickC.h>
void setup()
{
  Serial.begin(115200);
  M5.begin();
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.println("Connecting Bluetooth");
  BMDConnection.begin("Remote6");
  BMDConnection.clearPairing();
  BMDControl = BMDConnection.connect();
  M5.Lcd.println("Connection Succesful");
}
void loop()
{
  M5.update();
  if (M5.BtnA.wasReleased()) {
    BMDControl->record(true);
    M5.Lcd.println("A was pressed");
  }
  if (M5.BtnB.wasReleased()) {
    BMDControl->record(false);
     M5.Lcd.println("B was pressed");
  }
}

After adding the BMDConnection.clearPairing(); line i had a bit more success making them talk after the power cycle but no success reconnecting them.

@SwooshMihu that's because of this line:

BMDConnection.clearPairing();

Remove this line and reflash your device. This is only used when you want your stick to 'forget' your camera.

I encountered a similar situation, when the firmware is first uploaded, it looks for the camera’s bluetooth and connects to it, but after a reboot (of the camera or microcontroller) it does not connect.

I didn’t fix the error, but I understood where the reason was: BlueMagicCameraConnection.cpp
address = *getCameraAddress(); - error here

Steps:

BlueMagicCameraController *BlueMagicCameraConnection::connect(uint8_t index)
{
  if (_cameraControl != nullptr)
  {
    return _cameraControl;
    Serial.println("return _cameraControl;");
  }

  bool ok;
  bool scanned = scan(false, 5);

  // Step 2 - Specify your camera code exactly
  BLEAddress address = BLEAddress("CC:86:EC:67:3F:3F");
  Serial.println(address.toString().c_str());

  if (scanned)
  {
    int count = _bleScan->getResults().getCount();
    if (count > 0)
    {
      int foundIndex = count - 1;
      address = _bleScan->getResults().getDevice(foundIndex).getAddress();
      ok = connectToServer(address);
      // Step 1.1 - Add a code - when connecting the pointers for the first time, the address of your camera
      Serial.println("if (scanned) if (count > 0)");
      Serial.println(address.toString().c_str());
    }
  }
  else
  {
    // Step 1.2 - comment change address
    //address = *getCameraAddress();
    ok = connectToServer(address);
    Serial.println("if (scanned) else");
    Serial.println(address.toString().c_str());
  }

  if (ok)
  {
    setAuthentication(true);
    _pref->begin(_name.c_str(), false);
    _pref->putString("cameraAddress", address.toString().c_str());
    _pref->putBool("authenticated", getAuthentication());
    _pref->end();
    setCameraAddress(address);
    Serial.println("if (ok)");
    Serial.println(address.toString().c_str());
    return _cameraControl;
  }

  return nullptr;
}