vovagorodok / ArduinoBleOTA

Upload firmware over Bluetooth
MIT License
24 stars 8 forks source link

Remove advertising functionality from begin methods #20

Closed sdetweil closed 11 months ago

sdetweil commented 1 year ago

in my case I know when to advertise, , you should leave that up to the user.

this sort of goes with the MTU issue, #19

vovagorodok commented 1 year ago

in my case I know when to advertise, , you should leave that up to the user.

That's why we have two begin methods. First is with ble initialization and advertising for basic users. But second is without for advanced users and multiservice

this sort of goes with the MTU issue, https://github.com/vovagorodok/ArduinoBleOTA/issues/19

What do you mean?

sdetweil commented 1 year ago

but one inits the BLE system with a name.. no thanks.. and advertisises.. no thanks

    BLEDevice::init(deviceName);
    auto* server = BLEDevice::createServer();

    if(!begin(storage, hwName, hwVersion, swName, swVersion, enableUpload))
        return false;

    auto* advertising = server->getAdvertising();
    advertising->setScanResponse(true);
    advertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
    advertising->setMaxPreferred(0x12);
    return advertising->start();

the other creates the server .. no thanks and adds the service to the system.. no thanks.. and adds it to the advertisable data

 auto* server = BLEDevice::createServer();
    BLEDevice::setMTU(BLE_OTA_MTU_SIZE);

    bleOtaUploader.begin(storage);
    bleOtaUploader.setEnabling(enableUpload);
    auto* service = server->createService(BLE_OTA_SERVICE_UUID);

    auto* rxCharacteristic = service->createCharacteristic(
        BLE_OTA_CHARACTERISTIC_UUID_RX,
        NIMBLE_PROPERTY::WRITE_NR
    );
    rxCharacteristic->setCallbacks(this);

    auto* txCharacteristic = service->createCharacteristic(
        BLE_OTA_CHARACTERISTIC_UUID_TX,
        NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
    );
    this->txCharacteristic = txCharacteristic;

    begin(*service, hwName, hwVersion, swName, swVersion);

    auto* advertising = server->getAdvertising();
    advertising->addServiceUUID(BLE_OTA_SERVICE_UUID);
    return service->start();

i extended the second, pass in the server, get back the service

but I see that advertising side effect..

edit: this 'problem' was caused by a duplicate Advertising->addServiceUUID() (one in you lib one by me) I have a problem with nimble when calling begin during loop().. i get an empty service back.. no characteristics..

i don't want to expose the OTA service until its time to DO OTA to a specific device.. and thats my app/user decision..

vovagorodok commented 1 year ago

But Your case looks very specific. Most of users will prefer simple one/two line integration I guess.

sdetweil commented 1 year ago

I understand. just trying to implement some reasonable security.
and still be in control of what's happening.