Modified code.
checking self.wifi before connect to wifi.