Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
i = i + 1
try:
networkType = WeaveDeviceMgr.ParseNetworkType("thread")
scanResult = devMgr.ScanNetworks(networkType)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
print "ScanNetworks complete, %d network(s) found" % (len(scanResult))
i = 1
for net in scanResult:
print " Network %d" % (i)
net.Print(" ")
i = i + 1
print ''
print '#################################add-network#################################'
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
wifiSSID = "Wireless-1",
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = WeaveDeviceMgr.WiFiSecurityType_None)
try:
addResult = devMgr.AddNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
lastNetworkId = addResult
print "Add wifi network complete (network id = " + str(addResult) + ")"
try:
addResult = devMgr.AddNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
lastNetworkId = addResult
print "Add wifi network complete (network id = " + str(addResult) + ")"
print ''
print '#################################update-network#################################'
# networkInfo = WeaveDeviceMgr.NetworkInfo(networkId=lastNetworkId)
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
networkId=lastNetworkId,
wifiSSID = "Wireless-1",
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = WeaveDeviceMgr.WiFiSecurityType_None)
try:
devMgr.UpdateNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Update network complete"
print ''
thread-pskc or pskc
passphrase
...
"""
args = shlex.split(line)
if (len(args) == 0):
print "Usage:"
self.do_help('add-thread-network')
return
if (len(args) < 2):
print "Please specify the Network Name and Extended PAN Identifier"
return
networkInfo = WeaveDeviceMgr.NetworkInfo()
networkInfo.NetworkType = WeaveDeviceMgr.NetworkType_Thread
networkInfo.ThreadNetworkName = args[0]
try:
networkInfo.ThreadExtendedPANId = bytearray(binascii.unhexlify(args[1]))
if len(networkInfo.ThreadExtendedPANId) != 8:
print "Thread extended PAN id must be 8 bytes in hex"
return
except ValueError:
print "Invalid value specified for thread extended PAN id: " + args[1]
return
kvstart = 3 if (len(args) > 2 and len(args[2].split('=', 1)) == 1) else 2
if (kvstart > 2):
try:
if (len(args) == 0):
print "Usage:"
self.do_help('update-network')
return
if (len(args) < 1):
print "Please specify the network id"
return
networkId = self.parseNetworkId(args[0])
if (networkId == None):
return
self.lastNetworkId = networkId
networkInfo = WeaveDeviceMgr.NetworkInfo(networkId=networkId)
for updatedVal in args[1:]:
nameVal = updatedVal.split('=', 1)
if (len(nameVal) < 2):
print "Invalid argument: updatedVal"
return
try:
networkInfo.SetField(nameVal[0], nameVal[1])
except Exception, ex:
print str(ex)
return
try:
self.devMgr.UpdateNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
return
if (len(args) == 0):
print "Usage:"
self.do_help('add-wifi-network')
return
if (len(args) < 2):
print "Please specify WiFI security type"
return
securityType = WeaveDeviceMgr.ParseSecurityType(args[1])
if (securityType == None):
print "Unrecognized security type: " + args[1]
return
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
wifiSSID = args[0],
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = securityType)
if (securityType != WeaveDeviceMgr.WiFiSecurityType_None):
if (len(args) < 3):
print "Must supply WiFi key"
return
if (len(args) > 3):
print "Unexpected argument: " + args[3]
return
networkInfo.WiFiKey = args[2]
elif (len(args) > 2):
print "Unexpected argument: " + args[2]
optParser.add_option("-n", "--name", action="store", dest="threadNetworkName", type="string")
optParser.add_option("-k", "--key", action="store", dest="threadNetworkKey", type="string")
optParser.add_option("-s", "--pskc", action="store", dest="threadPSKc", type="string")
optParser.add_option("-p", "--panid", action="store", dest="threadPANId", type="hexint")
optParser.add_option("-c", "--channel", action="store", dest="threadChannel", type="int")
try:
(options, remainingArgs) = optParser.parse_args(args)
except SystemExit:
return
if (len(remainingArgs) > 0):
print "Unexpected argument: " + remainingArgs[0]
return
networkInfo = WeaveDeviceMgr.NetworkInfo()
networkInfo.NetworkType = WeaveDeviceMgr.NetworkType_Thread
if (options.threadNetworkName):
networkInfo.ThreadNetworkName = options.threadNetworkName
if (options.threadNetworkKey):
networkInfo.ThreadNetworkKey = bytearray(binascii.unhexlify(options.threadNetworkKey))
if (options.threadPSKc):
networkInfo.ThreadPSKc = bytearray(binascii.unhexlify(options.threadPSKc))
if (options.threadPANId):
networkInfo.ThreadPANId = options.threadPANId
if (networkInfo.ThreadPANId > 0xffff):
print "Thread PAN Id must be 16-bit hex value."
return
if (options.threadChannel):
networkInfo.ThreadChannel = options.threadChannel
if (networkInfo.ThreadChannel < 11 or networkInfo.ThreadChannel > 26):