Search code examples
qtwifidbusconnman

Dubs Connman wifi connect Qt


I'am working on an imx6, and i'am trying to connect to a wifi network through Dbus with a Qt application. The application connect correctly to connman via Dbus and i recieve correctly the wifi services. The problem is that when i try to connect to a wiif network i catch this error :

"Method "Connect" with signature "ss" on interface "net.connman.Service" doesn't exist

The code that i'am using in Qt application to coonect to a wifi network is:

QDBusInterface *iface =
new QDBusInterface("net.connman","/net/connman/technology/wifi","net.connman.Service",QDBusConnection::systemBus());

if (!iface->isValid())
{
    qDebug() << Q_FUNC_INFO << "Fail to connect to the Connman Technology interface: " << QDBusConnection::systemBus().lastError().message();
}



QDBusReply<void> reply = iface->call("Connect","/net/connman/service/wifi_88da1a4db14c_41684179_managed_psk","password");

if (!reply.isValid())
{
    qDebug() << "Call connect result: " << reply.error().message();
}

When i try to connect to the wifi network with shell commands using connmanctl it works like a charm.


Solution

  • I had the same problem on imx6. The solution which works for me is creating a configuration file for network before invoking Connect method.

    The file should be in /var/lib/connman and name [SSID].config . File content:

    [service_wifi_PUT_SERVICE_NAME]
    Name = PUT_SSID
    Type = wifi
    Passphrase = PUT_PASSWORD
    

    And try connecting in this way:

    QDBusInterface *iface =  new QDBusInterface("net.connman", QString{"/net/connman/service/%1"}.arg(SERVICE_NAME), "net.connman.Service", QDBusConnection::systemBus());
    QDBusReply<void> reply = iface->call("Connect");
    if(!reply.isValid() {
    ...