We don't need to introduce another variable if we check 'isConnected' only here. I use the wifi api instead as proposed by @alivedise.