Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3

Good day

Im trying to switch off an LED when my relay/hopper is not advertising. I switch the LED on successfully when transmission starts but I'm struggling to do the sd_ble_gap_adv_stop check to switch the led off. This is a simple relay/hopper and retransmits the MAC address of a received beacon + its own address. It works very well and I manage to stop the advertising successfully after a tiem out. Just need to switch the LED off.

The scanning part

static void advertising_init(void) // no more than 31 bytes 
{  
    uint32_t      err_code;
    ble_advdata_t advdata; // no more than 31 bytes
    uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

    ble_advdata_manuf_data_t manuf_specific_data;
    manuf_specific_data.company_identifier =  APP_COMPANY_IDENTIFIER;
    manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;

        if (g_setAdvData) // if a mac address is received from a beacon build a payload consisting of repeater mac + beacon mac
    {  

        //mac address of the repeater (this device) added to payload
        manuf_specific_data.data.p_data [6]=repeater_mac_addr.addr[0]; // Local mac address
        manuf_specific_data.data.p_data [7]=repeater_mac_addr.addr[1]; // Local mac address
        manuf_specific_data.data.p_data [8]=repeater_mac_addr.addr[2]; // Local mac address
        manuf_specific_data.data.p_data [9]=repeater_mac_addr.addr[3]; // Local mac address
        manuf_specific_data.data.p_data [10]=repeater_mac_addr.addr[4]; // Local mac address
        manuf_specific_data.data.p_data [11]=repeater_mac_addr.addr[5]; // Local mac address 
        //cant go higher than 22
       
       //mac address of the beacon (received by this device) added to payload
        manuf_specific_data.data.p_data [12]= Beacon_mac_addr[0]; // Beacon MAC address
        manuf_specific_data.data.p_data [13]= Beacon_mac_addr[1]; // Beacon MAC address
        manuf_specific_data.data.p_data [14]= Beacon_mac_addr[2]; // Beacon MAC address
        manuf_specific_data.data.p_data [15]= Beacon_mac_addr[3]; // Beacon MAC address
        manuf_specific_data.data.p_data [16]= Beacon_mac_addr[4]; // Beacon MAC address
        manuf_specific_data.data.p_data [17]= Beacon_mac_addr[5]; // Beacon MAC address
      
           g_setAdvData = false; // turn off the set adv data and wait for next mac to come
   }

//shows the manuf payload of ble 
/*NRF_LOG_RAW_INFO("%02x%02X%02X%02X%02X\n",
                    manuf_specific_data.data.p_data [15], manuf_specific_data.data.p_data [16],
                    manuf_specific_data.data.p_data [17], manuf_specific_data.data.p_data [18],
                    manuf_specific_data.data.p_data [19], manuf_specific_data.data.p_data [20]);*/

NRF_LOG_RAW_INFO("Re-transmitting initial scanner MAC %02x:%02x:%02x:%02x:%02x:%02x ",initial_scanner_mac_addr[5], initial_scanner_mac_addr[4], initial_scanner_mac_addr[3], initial_scanner_mac_addr[2], initial_scanner_mac_addr[1], initial_scanner_mac_addr[0])
NRF_LOG_RAW_INFO("Re-transmitting  Beacon found MAC  %02x:%02x:%02x:%02x:%02x:%02x\r\n",Beacon_mac_addr[0], Beacon_mac_addr[1], Beacon_mac_addr[2], Beacon_mac_addr[3], Beacon_mac_addr[4], Beacon_mac_addr[5])
        
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 9)); // green led  on to show advertising is on the go 
    //   nrf_delay_ms(10);
    //   nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 9)); // green led  off

    manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type             = BLE_ADVDATA_NO_NAME;
    advdata.flags                 = flags;
    advdata.p_manuf_specific_data = &manuf_specific_data;

    // Initialize advertising parameters (used when starting advertising).
    memset(&m_adv_params, 0, sizeof(m_adv_params));

    m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
    m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
    m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
    m_adv_params.duration        = 300;       // time out

    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
    APP_ERROR_CHECK(err_code);
}

end loop while waiting for new data to come in for retransmission. I think this is where I need to switch my " adv in progress LED off"

  for (;;)
      {

        if (      ) {nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 9));} // green led  off



      if(g_setAdvData)
                {

                 sd_ble_gap_adv_stop(m_adv_handle); 
                 
                    
                     advertising_init(); // load the new data for payload

                    //    if put something here to double check its not retransmitting something thats just been relayed, avoid an endless loop
                    //    {
                       advertising_start(); // start advertising

                    //    }
                      g_setAdvData = false; // turn of get new adv
                }

      idle_state_handle();
      }

From  what I have seen on the forum  here https://devzone.nordicsemi.com/f/nordic-q-a/14071/check-if-currently-advertising

in my "if (  ) " statement that is currently blank I need to check for a NRF_Success error code return but have not had any success.

any suggestions will be welcomed? :)