Skip to content

correctly shutdown / restart (stop advertising and resume) #107

Description

@infrafast

hello I made an end() method which is supposed to stop the BLEMIDI but none of the code after calling all of the end() and stop() below, the esp32 is still advertising ...
can you let me know how to properly shutdown it...

    virtual bool end() override{
      DEBUG_PRINT("\n%s::end()",interfaceName.c_str());          
      auto transport = bleMIDI.getTransport();  // ✅ On récupère le transport BLE
      hasBegun = false;
      if (transport) {
          if (hasBegun){
            transport->end();     
            BLEbleMIDI.end();    // does nothing                   
            BLEDevice::getAdvertising()->stop();            
          }else{
            DEBUG_PRINT("\n\ttransport->end() ignored (!hasBegun)");    
          }
          // bleMIDI.end() doesnt exists
          return true;
      }
      return false;    
    }  

and here is my begin() method which is called when enabling the service

    virtual bool begin(){
      DEBUG_PRINT("\n%s::begin()",interfaceName.c_str());          
      MIDIInterface::init();  
      bleInstancePtr = this;   // do not forget otherwise callback function will crash

      BLEbleMIDI.setHandleConnected(handleConnectedStatic);
      BLEbleMIDI.setHandleDisconnected(handleDisconnectedStatic);
      
      bleMIDI.setHandleSystemExclusive(handleSysexStatic);

      if (!hasBegun){
        if (state.enabled){
          setStatePending();            
          DEBUG_PRINT("\n\tbleMIDI.begin()");          
          bleMIDI.begin();                
          hasBegun = true;
        }else{
          DEBUG_PRINT("\n\tbleMIDI.begin() ignored (disabled)");          
        }
      }else{
        DEBUG_PRINT("\n\tbleMIDI.begin() ignored (hasBegun)");          
      }             
      return true;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions