src/eric7/MicroPython/Devices/CircuitPythonDevices.py

branch
eric7
changeset 10144
45a9177c8e77
parent 10138
56614cf9d03c
child 10153
ffe7432f716b
equal deleted inserted replaced
10143:bf84513859ca 10144:45a9177c8e77
909 return False, err 909 return False, err
910 910
911 result = json.loads(out.decode("utf-8").strip()) 911 result = json.loads(out.decode("utf-8").strip())
912 error = "" if result["connected"] else result["status"] 912 error = "" if result["connected"] else result["status"]
913 913
914 self._networkConnected = result["connected"]
915
916 return result["connected"], error 914 return result["connected"], error
917 915
918 def disconnectWifi(self): 916 def disconnectWifi(self):
919 """ 917 """
920 Public method to disconnect a device from the WiFi network. 918 Public method to disconnect a device from the WiFi network.
942 940
943 out, err = self.executeCommands(command, mode=self._submitMode) 941 out, err = self.executeCommands(command, mode=self._submitMode)
944 if err: 942 if err:
945 return False, err 943 return False, err
946 944
947 self._networkConnected = False
948
949 result = json.loads(out.decode("utf-8").strip()) 945 result = json.loads(out.decode("utf-8").strip())
950 return result["success"], result["status"] 946 return result["success"], result["status"]
947
948 def isWifiClientConnected(self):
949 """
950 Public method to check the WiFi connection status as client.
951
952 @return flag indicating the WiFi connection status
953 @rtype bool
954 """
955 command = """
956 def wifi_connected():
957 import wifi
958
959 r = wifi.radio
960 print(r.ipv4_address is not None)
961
962 wifi_connected()
963 del wifi_connected
964 """
965
966 out, err = self.executeCommands(command, mode=self._submitMode)
967 if err:
968 return False
969
970 return out.strip() == b"True"
971
972 def isWifiApConnected(self):
973 """
974 Public method to check the WiFi connection status as access point.
975
976 @return flag indicating the WiFi connection status
977 @rtype bool
978 """
979 command = """
980 def wifi_connected():
981 import wifi
982
983 r = wifi.radio
984 print(r.ipv4_address_ap is not None)
985 """
986
987 out, err = self.executeCommands(command, mode=self._submitMode)
988 if err:
989 return False
990
991 return out.strip() == b"True"
951 992
952 def writeCredentials(self, ssid, password): 993 def writeCredentials(self, ssid, password):
953 """ 994 """
954 Public method to write the given credentials to the connected device and modify 995 Public method to write the given credentials to the connected device and modify
955 the start script to connect automatically. 996 the start script to connect automatically.
1396 command, mode=self._submitMode, timeout=15000 1437 command, mode=self._submitMode, timeout=15000
1397 ) 1438 )
1398 if err: 1439 if err:
1399 return False, err 1440 return False, err
1400 1441
1401 self._networkConnected = True
1402
1403 return out.strip() == b"True", "" 1442 return out.strip() == b"True", ""
1404 1443
1405 def disconnectFromLan(self): 1444 def disconnectFromLan(self):
1406 """ 1445 """
1407 Public method to disconnect from the LAN. 1446 Public method to disconnect from the LAN.
1430 command, mode=self._submitMode, timeout=15000 1469 command, mode=self._submitMode, timeout=15000
1431 ) 1470 )
1432 if err: 1471 if err:
1433 return False, err 1472 return False, err
1434 1473
1435 self._networkConnected = False
1436
1437 return out.strip() == b"True", "" 1474 return out.strip() == b"True", ""
1475
1476 def isLanConnected(self):
1477 """
1478 Public method to check the LAN connection status.
1479
1480 @return flag indicating that the device is connected to the LAN
1481 @rtype bool
1482 """
1483 command = """{0}
1484 def is_connected():
1485 w5x00_init()
1486
1487 print(nic.link_status == 1 and nic.ifconfig[0] != b'\x00\x00\x00\x00')
1488
1489 is_connected()
1490 del is_connected, w5x00_init
1491 """.format(
1492 WiznetUtilities.cpyWiznetInit(),
1493 )
1494
1495 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
1496 if err:
1497 return False
1498
1499 return out.strip() == b"True"
1438 1500
1439 def checkInternetViaLan(self): 1501 def checkInternetViaLan(self):
1440 """ 1502 """
1441 Public method to check, if the internet can be reached (LAN variant). 1503 Public method to check, if the internet can be reached (LAN variant).
1442 1504

eric ide

mercurial