src/eric7/MicroPython/Devices/EspDevices.py

branch
eric7
changeset 10144
45a9177c8e77
parent 10138
56614cf9d03c
child 10153
ffe7432f716b
equal deleted inserted replaced
10143:bf84513859ca 10144:45a9177c8e77
758 try: 758 try:
759 error = self.__statusTranslations[result["status"]] 759 error = self.__statusTranslations[result["status"]]
760 except KeyError: 760 except KeyError:
761 error = str(result["status"]) 761 error = str(result["status"])
762 762
763 self._networkConnected = result["connected"]
764
765 return result["connected"], error 763 return result["connected"], error
766 764
767 def disconnectWifi(self): 765 def disconnectWifi(self):
768 """ 766 """
769 Public method to disconnect a device from the WiFi network. 767 Public method to disconnect a device from the WiFi network.
791 789
792 out, err = self.executeCommands(command, mode=self._submitMode) 790 out, err = self.executeCommands(command, mode=self._submitMode)
793 if err: 791 if err:
794 return False, err 792 return False, err
795 793
796 self._networkConnected = False
797
798 return out.decode("utf-8").strip() == "True", "" 794 return out.decode("utf-8").strip() == "True", ""
795
796 def isWifiClientConnected(self):
797 """
798 Public method to check the WiFi connection status as client.
799
800 @return flag indicating the WiFi connection status
801 @rtype bool
802 """
803 if self.hasCircuitPython():
804 return self.__cpyDevice.isWifiClientConnected()
805
806 command = """
807 def wifi_connected():
808 import network
809
810 wifi = network.WLAN(network.STA_IF)
811 print(wifi.isconnected())
812
813 wifi_connected()
814 del wifi_connected
815 """
816
817 out, err = self.executeCommands(command, mode=self._submitMode)
818 if err:
819 return False
820
821 return out.strip() == b"True"
822
823 def isWifiApConnected(self):
824 """
825 Public method to check the WiFi connection status as access point.
826
827 @return flag indicating the WiFi connection status
828 @rtype bool
829 """
830 if self.hasCircuitPython():
831 return self.__cpyDevice.isWifiApConnected()
832
833 command = """
834 def wifi_connected():
835 import network
836
837 wifi = network.WLAN(network.AP_IF)
838 print(wifi.isconnected())
839
840 wifi_connected()
841 del wifi_connected
842 """
843
844 out, err = self.executeCommands(command, mode=self._submitMode)
845 if err:
846 return False
847
848 return out.strip() == b"True"
799 849
800 def writeCredentials(self, ssid, password): 850 def writeCredentials(self, ssid, password):
801 """ 851 """
802 Public method to write the given credentials to the connected device and modify 852 Public method to write the given credentials to the connected device and modify
803 the start script to connect automatically. 853 the start script to connect automatically.

eric ide

mercurial