WiFi.beginAP() followed by WiFi.begin() failes

Hello,
I am trying to auto configure a MRK1000 wireless using the following idea:

  1. After reset MKR creates a local access point with WiFI.beginAP()
  2. connect PC to it and transmit the SSID and PASS of the local Wifi network
  3. connect MKR to the local network with WiFi.begin()

the code is attached below and returns WL_IDLE_STATUS when calling WiFi.begin(). It seems you cannot connect if you are not hard resetting the MKR. Is there any hack to do this?
There is no difference if I call WiFi.disconnect() between step 2) and 3), it never connects and it takes a long time to return from the begin() call.

Thanks
Markus

#include <SPI.h>
#include <WiFi101.h>


char ssid[] = "SSID";      // your network SSID (name) 
char pass[] = "PASS";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect.
  }
  
//   check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

     status = WiFi.beginAP("LaLa-net");
    if (status != WL_AP_LISTENING) {
      Serial.println("Creating access point failed");
    }
    else
      Serial.println("Creating access point succeeded");
    delay(5000);
  WiFi.disconnect();
     delay(5000); 
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
    Serial.print("Wifi Status:"); Serial.println(status);

  } 

  // you're connected now, so print out the status:
  printWifiStatus();
}

void loop() {
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

After poking around it seems that is a problem discovered before. I found a solution calling this:

WiFi.disconnect();
WiFi.init();

init() is not a public method so you have to alter the source of WiFi.h to move it from private to public.

Well, this is only a partial success :( It does connect to the local wifi network but WiFi.hostByName() does not resolve the URL.

Any suggestions anyone?

Markus