Aldebaran documentation What's new in NAOqi 2.4.3?

ALConnectionManager API

NAOqi Core - Overview | API | NetworkInfo | NetworkInfo-IPInfo


Namespace : AL

#include <alproxies/alconnectionmanagerproxy.h>

Event list

std::string ALConnectionManagerProxy::state()

Returns the global state of the network connectivity. Possible values are:

  • “online” if an Internet connection is available.
  • “ready” this state means that at least one service is successfully connected.
  • “offline” this state means there is no network connection.
#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use state Method"""

import qi
import argparse
import sys


def main(session):
    """
    This example uses the state method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    # Get network state.
    print "Network state: " + con_mng_service.state()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
Returns:The global state of the connection manager.
void ALConnectionManagerProxy::scan()

There are two overloads of this function:

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).

void ALConnectionManagerProxy::scan(const std::string& technology)

Scans for reachable services.

Parameters:
  • technology – The type of technology to scan.
AL::ALValue ALConnectionManagerProxy::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.

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use scan and services Methods"""

import qi
import argparse
import sys


def main(session):
    """
    This example uses the scan and services method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    #Scanning is required to update the services list
    con_mng_service.scan()
    services = con_mng_service.services()

    for service in services:
        network = dict(service)
        if network["Name"] == "":
            print "{hidden} " + network["ServiceId"]
        else:
            print network["Name"] + " " + network["ServiceId"]


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
AL::ALValue ALConnectionManagerProxy::technologies()

Returns an array of string representing the available technologies, possible values are:

  • “ethernet”
  • “wifi”
  • “bluetooth”
Returns:A list of available technologies.

Listing the available technologies

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use technologies Method"""

import qi
import argparse
import sys


def main(session):
    """
    This example uses the technologies method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    # Get the technologies.
    technologies = con_mng_service.technologies()
    if len(technologies) >0:
        print "available technology: "
        for technology in technologies:
            print "\t" + technology


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
AL::ALValue ALConnectionManagerProxy::service(const std::string& serviceId)

Returns the properties of a given service identifier, the NetworkInfo is represented as ALValue: ALValue representation of NetworkInfo.

Parameters:
  • serviceId – The identifier of the service to get the properties.
Returns:

the properties of the given service identifier.

Throw:

ALError when the service is not available.

Getting the properties of a service.

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use service Method"""

import qi
import argparse
import sys


def main(session, service_id):
    """
    This example uses the service method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    # Get service.
    service = con_mng_service.service(service_id)
    service = dict(service)
    print "Network Service: " + service_id
    for key, value in service.iteritems():
        print "\t" + key + ": " + str(value)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")
    parser.add_argument("--service_id", type=str, required=True,
                        help="The identifier for the service to connect.")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session, args.service_id)
void ALConnectionManagerProxy::connect(const std::string& serviceId)

Connects to a network service.

Parameters:
  • serviceId – The identifier for the service to connect.
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.

Connecting to a service.

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use connect Method"""

import qi
import argparse
import sys


def main(session, service_id):
    """
    This example uses the connect method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    # Connect.
    con_mng_service.connect(service_id)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")
    parser.add_argument("--service_id", type=str, required=True,
                        help="The identifier for the service to connect.")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session, args.service_id)
void ALConnectionManagerProxy::disconnect(const std::string& serviceId)

Disconnects from the service.

Parameters:
  • serviceId – The identifier of the service to disconnect.
Throw:

ALError when the service is not available.

Disconnecting a service

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use disconnect Method"""

import qi
import argparse
import sys


def main(session, service_id):
    """
    This example uses the disconnect method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    # Disconnect.
    con_mng_service.disconnect(service_id)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")
    parser.add_argument("--service_id", type=str, required=True,
                        help="The identifier for the service to disconnect.")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session, args.service_id)
void ALConnectionManagerProxy::forget(const std::string& serviceId)

Removes a favorite service. Requests the given serviceId to forget association information. This will set the favorite and auto-connect boolean to false.

Parameters:
  • serviceId – The identifier of the network to forget.
Throw:

ALError when the service is not available.

Removing a preferred service.

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use forget Method"""

import qi
import argparse
import sys


def main(session, service_id):
    """
    This example uses the forget method.
    """
    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    # Forget.
    service = con_mng_service.forget(service_id)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")
    parser.add_argument("--service_id", type=str, required=True,
                        help="The identifier for the service to forget.")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session, args.service_id)
void ALConnectionManagerProxy::setServiceConfiguration(const AL::ALValue& configuration)

Requests to apply static service configuration. The following properties are available for static settings.

  • Domains
  • Nameservers
  • IPv4
  • IPv6 Experimental
Parameters:
  • serviceId – A NetworkInfo contained in a ALValue to apply as configuration.
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

NetworkInfo

void ALConnectionManagerProxy::setServiceInput(const AL::ALValue& input)

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:
  • input – An Input object contained in an ALValue.
Throw:

ALError when the service is not available, or when the input is not valid.

void ALConnectionManagerProxy::enableTethering(const std::string& technology)

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:
  • technology – The type of technology on which enabling tethering mode. Only support “bluetooth” and “wifi”
Throw:

ALError when the technology is not supported by tethering mode.

Enabling Tethering

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use enableTethering Method"""

import qi
import argparse
import sys


def main(session, args):
    """
    This example uses the enableTethering method.
    """
    technology =  args.technology
    passphrase =  args.passphrase
    service_name =  args.service_name

    # Get the service ALConnectionManager.

    con_mng_service = session.service("ALConnectionManager")

    passphrase =  args.passphrase
    service_name =  args.service_name

    # Enable Tethering on a new technology with pass
    if (passphrase != None and service_name != None):
        con_mng_service.enableTethering(technology, service_name, passphrase)

    # Enable Tethering on a new technology without pass
    else :
        con_mng_service.enableTethering(technology)

    if alconnman.getTetheringEnable(technology) == True:
        print "tethering is enabled"
    else:
        print "tethering is disabled"


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")
    parser.add_argument("--technology", type=str, required=True,
                        help="The technology you want to enable tethering.")
    parser.add_argument("--passphrase", type=str,
                        help="The WPA2 passphrase to connect to the created network.")
    parser.add_argument("--service_name", type=str,
                        help="The name of the network to create.")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session, args)
void ALConnectionManagerProxy::enableTethering(const std::string& technology, const std::string& name, const std::string& passphrase)

Creates a WPA2 secured Network Access Point on a given technology and share Internet connection if any.

Parameters:
  • technology – The type of technology on which enabling tethering mode. Only support “wifi”
  • name – The name of the network to create.

A valid network name has a maximum length of 32 characters and a minimum of 1 characters.

Parameters:
  • passphrase – The WPA2 passphrase to connect to the created network.

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.
void ALConnectionManagerProxy::disableTethering(const std::string& technology)

Disables the Tethering mode.

Parameters:
  • technology – The type of technology on which disabling tethering mode.
Throw:

ALError when the technology is not supported by tethering mode.

bool ALConnectionManagerProxy::getTetheringEnable(const std::string& technology)
Parameters:
  • technology – The type of technology.
Returns:

A boolean, true if Tethering mode is enabled false instead.

Throw:

ALError when the technology is not supported by tethering mode.

std::string ALConnectionManagerProxy::tetheringName(const std::string& technology)
Parameters:
  • technology – The type of technology. only support “wifi”
Returns:

Returns the service name used for the tethering mode.

Throw:

ALError when the technology is not supported by tethering mode.

std::string ALConnectionManagerProxy::tetheringPassphrase(const std::string& technology)
Parameters:
  • technology – The type of technology. only support “wifi”
Returns:

Returns the passphrase used for the tethering mode.

Throw:

ALError when the technology is not supported by tethering mode.

std::vector<std::string> ALConnectionManagerProxy::countries()
Returns:Returns an std::vector<std::string> of known country codes as defined in ISO-3166-1.
std::string ALConnectionManagerProxy::country()
Returns:Returns the country code currently in use for wireless regulatory.
void ALConnectionManagerProxy::setCountry(const std::string& country)
Parameters:
  • country – The country code to set as defined in ISO-3166-1, to apply as wireless regulatory.
Throw:

ALError when the country code is not known.

AL::ALValue ALConnectionManagerProxy::interfaces()

Warning

API subject to change.

Returns:Returns a list of pairs: interface name, MAC address.

ALConnectionManagerProxy Events

Event: "NetworkStateChanged"
callback(std::string eventName, const std::string &state, std::string subscriberIdentifier)

Raised when the global connectivity state changed.

Parameters:
  • eventName (std::string) – “NetworkStateChanged”
  • state – The state of the connection manager (same value as ALConnectionManagerProxy::state ).
  • subscriberIdentifier (std::string) –
Event: "NetworkDefaultTechnologyChanged"
callback(std::string eventName, const std::string &techology, std::string subscriberIdentifier)

Raised when default technology changed.

Parameters:
  • eventName (std::string) – “NetworkDefaultTechnologyChanged”
  • technology – The new technology used for outgoing connection.
  • subscriberIdentifier (std::string) –
Event: "NetworkServiceStateChanged"
callback(std::string eventName, AL::ALValue &serviceState, std::string subscriberIdentifier)

Raised when a service state is changed.

Parameters:
  • eventName (std::string) – “NetworkServiceStateChanged”
  • state – A pair which contains the serviceId and the state of the service.
  • subscriberIdentifier (std::string) –

The state of the service uses the same values as NetworkInfo::state.

Event: "NetworkServiceRemoved"
callback(std::string eventName, const std::string &serviceId, std::string subscriberIdentifier)

Raised when a service is removed from the service list.

Parameters:
  • eventName (std::string) – “NetworkServiceRemoved”
  • serviceId – the service identifier of the removed service.
  • subscriberIdentifier (std::string) –
Event: "NetworkServiceAdded"
callback(std::string eventName, const std::string &serviceId, std::string subscriberIdentifier)

Raised when a service is added to the service list.

Parameters:
  • eventName (std::string) – “NetworkServiceAdded”
  • serviceId – the service identifier of the added service.
  • subscriberIdentifier (std::string) –
Event: "NetworkServiceInputRequired"
callback(std::string eventName, const AL::ALValue &inputRequest, std::string subscriberIdentifier)

Raised when a connection to a service requires input information to succeed.

Parameters:
  • eventName (std::string) – “NetworkServiceInputRequired”
  • inputRequest – the requested inputs stored in a ALValue see ALValue Input Request
  • subscriberIdentifier (std::string) –

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

Event: "NetworkTechnologyAdded"
callback(std::string eventName, const std::string &technology, std::string subscriberIdentifier)

Raised when a new technology is available.

Parameters:
  • eventName (std::string) – “NetworkTechnologyAdded”
  • technology – the name of the technology (same values as ALConnectionManagerProxy::technologies).
  • subscriberIdentifier (std::string) –
Event: "NetworkTechnologyRemoved"
callback(std::string eventName, const std::string &technology, std::string subscriberIdentifier)

Raised when a new technology is no longer available.

Parameters:
  • eventName (std::string) – “NetworkTechnologyRemoved”
  • technology – the name of the technology (same values as ALConnectionManagerProxy::technologies).
  • subscriberIdentifier (std::string) –
Event: "NetworkConnectStatus"
callback(std::string eventName, const AL::ALValue &status, std::string subscriberIdentifier)

Raised when a call to ALConnectionManagerProxy::connect is finished.

Parameters:
  • eventName (std::string) – “NetworkConnectStatus”
  • status

    An array informing about the return of the connect method.

    Entry ‘0’ is an std::string containing the serviceId we try to connect to.

    The entry ‘1’ is a boolean, ‘true’ if the connect method has succeeded, ‘false’ otherwise.

    In case of failure the error message is in the entry ‘3’, as a std::string.

  • subscriberIdentifier (std::string) –

ALValue Input Request

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:

  • “Passphrase” for a WEP or WPA/WPA2 passphrase
  • “WPS” for a Wireless Protected Setup enabled Access Point
  • “Name” for the name of a hidden network.
  • “Identity” for a WPA Enterprise Network. Experimental
  • “Username” for a WISPr enabled hotspot. Experimental
  • “Password” for the user password for WPA enterprise or WiSPr Access Point. Experimental
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

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:

  • “psk” for a WPA/WPA2 passphrase,
  • “wpspin” for a WPS pin code,
  • “string” for a non secret text, or
  • “passphrase” or a WPA Enterprise passphrase.

ALValue Input Reply

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”