如何使用ALConnectionManager将NAO Robot连接到wifi,而不使用webpage

2024-09-30 01:31:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用ALConnectionManager把我的NAO机器人连接到一个新的wifi网络,这样我就不用使用这个网页了。使用PythonAPI比点击网页好。。。在


Tags: 网络网页pythonapi机器人wifinaoalconnectionmanager
1条回答
网友
1楼 · 发布于 2024-09-30 01:31:28

所以我发现,虽然不是很聪明,但它在2.x.x版本上运行得很好。。。在

    def connect(strSsid, strPassword):
        print( "INF: trying to connect to '%s', with some password..." % (strSsid) )
        self.cm = naoqi.ALProxy( "ALConnectionManager")
        self.cm.scan();
        aS = self.cm.services();
        bFound = False;
        for s in aS:
            print( "\nService: %s" % s )
            strServiceID = None;
            for attr in s:
                attrName, attrValue = attr;
                if( attrName == "ServiceId" ):
                    strServiceID = attrValue;
                if( attrName == "Name" and attrValue == strSsid ): # ASSUME, serviceID always set before Name
                    assert( strServiceID != None );
                    print( "INF: Good found the right wifi, ServiceID: '%s'\n" % strServiceID )
                    bFound = True;
                    break;
            if( bFound ):
                break;
        # for each services - end
        if( bFound ):
            # real connection
            aServiceInput = [];
            aServiceInput.append( ["ServiceId", strServiceID ] );
            aServiceInput.append( ["Passphrase", strPassword ] );
            aServiceInput.append( ["PrivateKeyPassphrase", strPassword ] );         # don't know wich one is usefull!
#            aServiceInput.append( ["Favorite", True ] ); # not working
            print( "DBG: ServiceInput: %s" % aServiceInput )
            retVal = self.cm.setServiceInput( aServiceInput );
            print( "DBG: setServiceInput return: %s" % str(retVal) )
            retVal = self.cm.connect( strServiceID );
            print( "DBG: connect return: %s" % str(retVal) )

相关问题 更多 >

    热门问题