src/eric7/MicroPython/Devices/DeviceBase.py

branch
eric7
changeset 10144
45a9177c8e77
parent 10138
56614cf9d03c
child 10153
ffe7432f716b
equal deleted inserted replaced
10143:bf84513859ca 10144:45a9177c8e77
68 <ul> 68 <ul>
69 <li>hasWifi: check, if the board has WiFi functionality</li> 69 <li>hasWifi: check, if the board has WiFi functionality</li>
70 <li>getWifiData: get WiFi status data</li> 70 <li>getWifiData: get WiFi status data</li>
71 <li>connectWifi: connect to a WiFi network</li> 71 <li>connectWifi: connect to a WiFi network</li>
72 <li>disconnectWifi: disconnect from a WiFi network</li> 72 <li>disconnectWifi: disconnect from a WiFi network</li>
73 <li>isWifiClientConnected: check the WiFi connection status as client</li>
74 <li>isWifiApConnected: check the WiFi connection status as access point</li>
73 <li>writeCredentials: save the WiFi credentials to the board and create 75 <li>writeCredentials: save the WiFi credentials to the board and create
74 functionality to auto-connect at boot time</li> 76 functionality to auto-connect at boot time</li>
75 <li>removeCredentials: remove the saved credentials</li> 77 <li>removeCredentials: remove the saved credentials</li>
76 <li>checkInternet: check, if internet access is possible</li> 78 <li>checkInternet: check, if internet access is possible</li>
77 <li>scanNetworks: scan for available WiFi networks</li> 79 <li>scanNetworks: scan for available WiFi networks</li>
90 <li>getDeviceScan: scan for visible Bluetooth devices</li> 92 <li>getDeviceScan: scan for visible Bluetooth devices</li>
91 </ul> 93 </ul>
92 94
93 Supported Ethernet commands are: 95 Supported Ethernet commands are:
94 <ul> 96 <ul>
95 <li>hasEthernet: check, if the board has Ethernet functionality 97 <li>hasEthernet: check, if the board has Ethernet functionality</li>
96 <li>getEthernetStatus: get Ethernet status data 98 <li>getEthernetStatus: get Ethernet status data</li>
97 <li>connectToLan: connect to an Ethernet network 99 <li>connectToLan: connect to an Ethernet network</li>
98 <li>disconnectFromLan: disconnect from an Ethernet network 100 <li>disconnectFromLan: disconnect from an Ethernet network</li>
99 <li>checkInternetViaLan: check, if internet access via LAN is possible 101 <li>isLanConnected: check the LAN connection status</li>
100 <li>deactivateEthernet: deactivate the Ethernet interface 102 <li>checkInternetViaLan: check, if internet access via LAN is possible</li>
103 <li>deactivateEthernet: deactivate the Ethernet interface</li>
101 <li>writeLanAutoConnect: save IPv4 parameters to the board and create a script 104 <li>writeLanAutoConnect: save IPv4 parameters to the board and create a script
102 to connect the board to the LAN 105 to connect the board to the LAN</li>
103 <li>removeLanAutoConnect: remove the IPv4 parameters and script from the board 106 <li>removeLanAutoConnect: remove the IPv4 parameters and script from the board</li>
104 </ul> 107 </ul>
105 """ 108 """
106 109
107 def __init__(self, microPythonWidget, deviceType, parent=None): 110 def __init__(self, microPythonWidget, deviceType, parent=None):
108 """ 111 """
119 122
120 self._deviceType = deviceType 123 self._deviceType = deviceType
121 self._interface = None 124 self._interface = None
122 self.microPython = microPythonWidget 125 self.microPython = microPythonWidget
123 self._deviceData = {} # dictionary with essential device data 126 self._deviceData = {} # dictionary with essential device data
124 self._networkConnected = False # trace the network connection status
125 127
126 self._submitMode = "raw" # default is 'raw' mode to submit commands 128 self._submitMode = "raw" # default is 'raw' mode to submit commands
127 129
128 def setConnected(self, connected): 130 def setConnected(self, connected):
129 """ 131 """
225 """ 227 """
226 return ( 228 return (
227 self.checkDeviceData() 229 self.checkDeviceData()
228 and self._deviceData["mpy_name"].lower() == "circuitpython" 230 and self._deviceData["mpy_name"].lower() == "circuitpython"
229 ) 231 )
230
231 def isNetworkConnected(self):
232 """
233 Public method to check, if the network interface (WiFi or Ethernet) is
234 connected.
235
236 @return flag indicating the network connection state
237 @rtype bool
238 """
239 return self._networkConnected
240 232
241 def submitMode(self): 233 def submitMode(self):
242 """ 234 """
243 Public method to get the submit mode of the device. 235 Public method to get the submit mode of the device.
244 236
1453 raise OSError(self._shortError(err)) 1445 raise OSError(self._shortError(err))
1454 1446
1455 return ast.literal_eval(out.decode("utf-8")) 1447 return ast.literal_eval(out.decode("utf-8"))
1456 1448
1457 ################################################################## 1449 ##################################################################
1450 ## Methods below general network related methods
1451 ##################################################################
1452
1453 def isNetworkConnected(self):
1454 """
1455 Public method to check, if the network interface (WiFi or Ethernet) is
1456 connected.
1457
1458 @return flag indicating the network connection state
1459 @rtype bool
1460 """
1461 # Ask the device if that is true.
1462 if self.hasEthernet()[0]:
1463 return self.isLanConnected()
1464 elif self.hasWifi():
1465 return self.isWifiClientConnected()
1466 else:
1467 return False
1468
1469 ##################################################################
1458 ## Methods below implement WiFi related methods 1470 ## Methods below implement WiFi related methods
1459 ################################################################## 1471 ##################################################################
1460 1472
1461 def hasWifi(self): 1473 def hasWifi(self):
1462 """ 1474 """
1506 1518
1507 @return tuple containing a flag indicating success and an error string 1519 @return tuple containing a flag indicating success and an error string
1508 @rtype tuple of (bool, str) 1520 @rtype tuple of (bool, str)
1509 """ 1521 """
1510 return True, "" 1522 return True, ""
1523
1524 def isWifiClientConnected(self):
1525 """
1526 Public method to check the WiFi connection status as client.
1527
1528 @return flag indicating the WiFi connection status
1529 @rtype bool
1530 """
1531 return False
1532
1533 def isWifiApConnected(self):
1534 """
1535 Public method to check the WiFi connection status as access point.
1536
1537 @return flag indicating the WiFi connection status
1538 @rtype bool
1539 """
1540 return False
1511 1541
1512 def writeCredentials(self, ssid, password): # noqa: U100 1542 def writeCredentials(self, ssid, password): # noqa: U100
1513 """ 1543 """
1514 Public method to write the given credentials to the connected device and modify 1544 Public method to write the given credentials to the connected device and modify
1515 the start script to connect automatically. 1545 the start script to connect automatically.
1675 1705
1676 @return tuple containing a flag indicating success and an error message 1706 @return tuple containing a flag indicating success and an error message
1677 @rtype tuple of (bool, str) 1707 @rtype tuple of (bool, str)
1678 """ 1708 """
1679 return True, "" 1709 return True, ""
1710
1711 def isLanConnected(self):
1712 """
1713 Public method to check the LAN connection status.
1714
1715 @return flag indicating that the device is connected to the LAN
1716 @rtype bool
1717 """
1718 return False
1680 1719
1681 def checkInternetViaLan(self): 1720 def checkInternetViaLan(self):
1682 """ 1721 """
1683 Public method to check, if the internet can be reached (LAN variant). 1722 Public method to check, if the internet can be reached (LAN variant).
1684 1723

eric ide

mercurial