Overview - API | NetworkInfo | NetworkInfo-IPInfo
ALConnectionManager provides methods to manage the network connectivity. It contains commands allowing you to configure or connect a network, but also to get the network properties or to create a network.
As any module, this module inherits methods from ALModule API. It also has the following specific methods:
Returns the global state of the network connectivity. Possible values are:
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
NAO_IP = "127.0.0.1"
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
print "network state: " + alconnman.state()
Returns: | The global state of the connection manager. |
---|
Scan for neighbor services on all available technologies. This is useful to refresh the list of services, which disappears after a while(specially for WiFi services).
Returns the list of all services with their properties. It might be useful to call the ALConnectionManagerProxy::scan() method before.
Returns: | An array of NetworkInfo contained in an ALValue. ALValue NetworkInfo. |
---|
Listing the available services.
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
NAO_IP = "127.0.0.1"
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
#Scanning is required to update the services list
alconnman.scan()
services = alconnman.services()
for service in services:
network = dict(service)
if network["Name"] == "":
print "{hidden} " + network["ServiceId"]
else:
print network["Name"] + " " + network["ServiceId"]
Returns an array of string representing the available technologies, possible values are:
Returns: | A list of available technologies. |
---|
Listing the available technologies
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
NAO_IP = "127.0.0.1"
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
technologies = alconnman.technologies()
if len(technologies) >0:
print "available technology: "
for technology in technologies:
print "\t" + technology
Returns the properties of a given service identifier, the NetworkInfo is represented as ALValue: ALValue representation of NetworkInfo.
Parameters: |
|
---|---|
Returns: | the properties of the given service identifier. |
Throw : | ALError when the service is not available. |
Getting the properties of a service.
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
import sys
NAO_IP = "127.0.0.1"
if len(sys.argv) != 2:
print sys.argv[0] + " <serviceId>"
sys.exit(1)
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
try:
service = alconnman.service(sys.argv[1])
except Exception as e:
print e.what()
sys.exit(1)
service = dict(service)
print "Network Service: " + sys.argv[1]
for key, value in service.iteritems():
print "\t" + key + ": " + str(value)
Connects to a network service.
Parameters: |
|
---|---|
Throws : | ALError when the service not available. |
Note
If some information are required to connect to this service, like a passphrase or the service name (for hidden services) an event will be raised.
See also
Connecting to a service.
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
import sys
NAO_IP = "127.0.0.1"
if len(sys.argv) != 2:
print sys.argv[0] + " <serviceId>"
sys.exit(1)
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
try:
alconnman.connect(sys.argv[1])
except Exception as e:
print e.what()
sys.exit(1)
Disconnects from the service.
Parameters: |
|
---|---|
Throw : | ALError when the service is not available. |
Disconnecting a service
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
import sys
NAO_IP = "127.0.0.1"
if len(sys.argv) != 2:
print sys.argv[0] + " <serviceId>"
sys.exit(1)
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
try:
alconnman.disconnect(sys.argv[1])
except Exception as e:
print e.what()
sys.exit(1)
Removes a favorite service. Requests the given serviceId to forget association information. This will set the favorite and auto-connect boolean to false.
Parameters: |
|
---|---|
Throw : | ALError when the service is not available. |
Removing a preferred service.
# -*- encoding: UTF-8 -*-
#!/usr/bin/env python
from naoqi import ALProxy
import sys
NAO_IP = "127.0.0.1"
if len(sys.argv) != 2:
print sys.argv[0] + " <serviceId>"
sys.exit(1)
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
try:
service = alconnman.forget(sys.argv[1])
except Exception as e:
print e.what()
sys.exit(1)
Requests to apply static service configuration. The following properties are available for static settings.
Parameters: |
|
---|---|
Throw : | ALError when the service is not available, when the configuration is not valid or when the service doesn’t requires an input. |
See also
Provides the connection manager module with the inputs required to finish a pending connection. This method must be called when receiving the NetworkServiceInputRequired event.
Parameters: |
|
---|---|
Throw : | ALError when the service is not available, or when the input is not valid. |
See also
Scans for reachable services.
Parameters: |
|
---|
Creates a Network Access Point on a given technology and share Internet connection if any. For WiFi technology you have to set the Name and the Passphrase before.
Parameters: |
|
---|---|
Throw : | ALError when the technology is not supported by tethering mode. |
Enabling Tethering
#!/usr/bin/env python
from naoqi import ALProxy
import sys
import time
NAO_IP = "127.0.0.1"
if len(sys.argv) != 2 and len(sys.argv) != 4:
print sys.argv[0] + " <technology> [Name] [Passphrase]"
sys.exit(1)
alconnman = ALProxy("ALConnectionManager", NAO_IP, 9559)
technology = sys.argv[1]
if len(sys.argv) == 4:
name = sys.argv[2]
passphrase = sys.argv[3]
try:
alconnman.enableTethering(technology, name, passphrase)
except Exception as e:
print e
sys.exit(1)
else:
try:
alconnman.enableTethering(technology)
time.sleep(2)
except Exception as e:
print e
sys.exit(1)
if alconnman.getTetheringEnable(technology) == True:
print "tethering is enabled"
else:
print "tethering is disabled"
Creates a WPA2 secured Network Access Point on a given technology and share Internet connection if any.
Parameters: |
|
---|
A valid network name has a maximum length of 32 characters and a minimum of 1 characters.
Parameters: |
|
---|
A valid WPA passphrase has a maximum length of 63 characters and a minimum of 8 characters.
Throw : | ALError when the technology is not supported by tethering mode. |
---|
Disables the Tethering mode.
Parameters: |
|
---|---|
Throw : | ALError when the technology is not supported by tethering mode. |
Parameters: |
|
---|---|
Returns: | A boolean, true if Tethering mode is enabled false instead. |
Throw : | ALError when the technology is not supported by tethering mode. |
Parameters: |
|
---|---|
Returns: | Returns the service name used for the tethering mode. |
Throw : | ALError when the technology is not supported by tethering mode. |
Parameters: |
|
---|---|
Returns: | Returns the passphrase used for the tethering mode. |
Throw : | ALError when the technology is not supported by tethering mode. |
Raised when the global connectivity state changed.
Parameters: |
|
---|
Raised when default technology changed.
Parameters: |
|
---|
Raised when a service state is changed.
Parameters: |
|
---|
The state of the service uses the same values as NetworkInfo::state().
Raised when a service is removed from the service list.
Parameters: |
|
---|
Raised when a service is added to the service list.
Parameters: |
|
---|
Raised when a connection to a service requires input information to succeed.
Parameters: |
|
---|
When this event is reveived you have to provide the required input using ALConnectionManagerProxy::setServiceInput().
Some examples of possible reply are available bellow. ALValue Input Reply
Raised when a new technology is available.
Parameters: |
|
---|
Raised when a new technology is no longer available.
Parameters: |
|
---|
This ALValue notifies the needed inputs to succeed in a network connection.
The Input Request is an array of n-pair (key, value).
All the requests contain the key “Network”, the identifier for the network service.
The different keys could be:
Key | Value type | Value content |
---|---|---|
“ServiceId” | String | The service identifier |
“Passphrase” | ALValue | ALValue Input Details |
“WPS” | ALValue | ALValue Input Details |
“Name” | ALValue | ALValue Input Details |
“Identity” | ALValue | ALValue Input Details |
“Password” | ALValue | ALValue Input Details |
“Username” | ALValue | ALValue Input Details |
The Input Details is an array of n-pair (key, value).
A network service may support several authentication methods, in this case it will ask you which method you want to use before requesting further inputs depending on the chosen authentication method. For example most of the recent Access Point support the WPA2 and the WPS as alternative method for the authentication.
The possible keys for the Input Details are:
Key | Value type | Value content |
---|---|---|
“Requirement” | string | which represents the requirement for the input Possible values are “Mandatory” or “alternate” |
“Alternates” | array of string | representing the alternatives method. |
“Type” | string | The type of the requested input. This can be:
|
The Input Reply is an array of n-pair (key, value).
All the replies to request input must contain the key “ServiceId” with the network service identifier as value.
The Input Reply must also contain all the mandatory fields requested by the event NetworkServiceInputRequired().
Examples:
ALValue reply for a WPA/WPA2 Enabled Access Point.
Key |
Value content |
---|---|
“ServiceId” |
string |
“Passphrase” |
“Mysecretpassphrase” |
ALValue reply for a WPA/WPA2 Enabled Access Point with hidden SSID.
Key |
Value content |
---|---|
“ServiceId” |
string |
“Passphrase” |
“Mysecretpassphrase” |
“Name” |
“MyHiddenSSID” |
ALValue reply for a WPS Enabled Access Point with hidden SSID, using the WPS push button method.
Key |
Value content |
---|---|
“ServiceId” |
string |
“WPS” |
“’” (reply an empty string to select push button or give a PIN code to select PIN code method) |
“Name” |
“MyHiddenSSID” |