src/eric7/MicroPython/Devices/RP2040Devices.py

branch
eric7
changeset 10144
45a9177c8e77
parent 10138
56614cf9d03c
child 10153
ffe7432f716b
equal deleted inserted replaced
10143:bf84513859ca 10144:45a9177c8e77
712 result["status"] 712 result["status"]
713 ] 713 ]
714 except KeyError: 714 except KeyError:
715 error = str(result["status"]) 715 error = str(result["status"])
716 716
717 self._networkConnected = result["connected"]
718
719 return result["connected"], error 717 return result["connected"], error
720 718
721 def disconnectWifi(self): 719 def disconnectWifi(self):
722 """ 720 """
723 Public method to disconnect a device from the WiFi network. 721 Public method to disconnect a device from the WiFi network.
759 757
760 out, err = self.executeCommands(command, mode=self._submitMode) 758 out, err = self.executeCommands(command, mode=self._submitMode)
761 if err: 759 if err:
762 return False, err 760 return False, err
763 761
764 self._networkConnected = False
765
766 return out.decode("utf-8").strip() == "True", "" 762 return out.decode("utf-8").strip() == "True", ""
763
764 def isWifiClientConnected(self):
765 """
766 Public method to check the WiFi connection status as client.
767
768 @return flag indicating the WiFi connection status
769 @rtype bool
770 """
771 if self._deviceData["wifi_type"] == "picow":
772 command = """
773 def wifi_connected():
774 import network
775
776 wifi = network.WLAN(network.STA_IF)
777 print(wifi.isconnected())
778
779 wifi_connected()
780 del wifi_connected
781 """
782 elif self._deviceData["wifi_type"] == "picowireless":
783 command = """
784 def wifi_connected():
785 import picowireless as pw
786
787 print(pw.get_connection_status() == 3)
788
789 wifi_connected()
790 del wifi_connected
791 """
792 else:
793 return super().isWifiClientConnected()
794
795 out, err = self.executeCommands(command, mode=self._submitMode)
796 if err:
797 return False
798
799 return out.strip() == b"True"
800
801 def isWifiApConnected(self):
802 """
803 Public method to check the WiFi connection status as access point.
804
805 @return flag indicating the WiFi connection status
806 @rtype bool
807 """
808 if self._deviceData["wifi_type"] == "picow":
809 command = """
810 def wifi_connected():
811 import network
812
813 wifi = network.WLAN(network.AP_IF)
814 print(wifi.isconnected())
815
816 wifi_connected()
817 del wifi_connected
818 """
819 elif self._deviceData["wifi_type"] == "picowireless":
820 command = """
821 def wifi_connected():
822 import picowireless as pw
823
824 print(pw.get_connection_status() == 8)
825
826 wifi_connected()
827 del wifi_connected
828 """
829 else:
830 return super().isWifiClientConnected()
831
832 out, err = self.executeCommands(command, mode=self._submitMode)
833 if err:
834 return False
835
836 return out.strip() == b"True"
767 837
768 def writeCredentials(self, ssid, password): 838 def writeCredentials(self, ssid, password):
769 """ 839 """
770 Public method to write the given credentials to the connected device and modify 840 Public method to write the given credentials to the connected device and modify
771 the start script to connect automatically. 841 the start script to connect automatically.
1611 command, mode=self._submitMode, timeout=15000 1681 command, mode=self._submitMode, timeout=15000
1612 ) 1682 )
1613 if err: 1683 if err:
1614 return False, err 1684 return False, err
1615 1685
1616 self._networkConnected = True
1617
1618 return out.strip() == b"True", "" 1686 return out.strip() == b"True", ""
1619 1687
1620 def disconnectFromLan(self): 1688 def disconnectFromLan(self):
1621 """ 1689 """
1622 Public method to disconnect from the LAN. 1690 Public method to disconnect from the LAN.
1645 command, mode=self._submitMode, timeout=15000 1713 command, mode=self._submitMode, timeout=15000
1646 ) 1714 )
1647 if err: 1715 if err:
1648 return False, err 1716 return False, err
1649 1717
1650 self._networkConnected = False
1651
1652 return out.strip() == b"True", "" 1718 return out.strip() == b"True", ""
1719
1720 def isLanConnected(self):
1721 """
1722 Public method to check the LAN connection status.
1723
1724 @return flag indicating that the device is connected to the LAN
1725 @rtype bool
1726 """
1727 command = """{0}
1728 def is_connected():
1729 import network
1730
1731 w5x00_init()
1732
1733 print(nic.isconnected())
1734
1735 is_connected()
1736 del is_connected, w5x00_init
1737 """.format(
1738 WiznetUtilities.mpyWiznetInit(),
1739 )
1740
1741 out, err = self.executeCommands(command, mode=self._submitMode)
1742 if err:
1743 return False
1744
1745 return out.strip() == b"True"
1653 1746
1654 def checkInternetViaLan(self): 1747 def checkInternetViaLan(self):
1655 """ 1748 """
1656 Public method to check, if the internet can be reached (LAN variant). 1749 Public method to check, if the internet can be reached (LAN variant).
1657 1750

eric ide

mercurial