Is it possible that when wifiManager.connection.status is "connecting" or "connected" but wifiManager.connection.network is null? If yes, I would suggest to use another string or at least assign an empty string to ssid.