# Detect if wifi is connected

**URL:** <https://forums.balena.io/t/detect-if-wifi-is-connected/473>\
**Category:** Product support\
**Created:** [December 30, 2016, 3:32pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473 "2016-12-30T15:32:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![keithejc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/keithejc/32/141_2.png) [@keithejc](https://forums.balena.io/u/keithejc)\
**Post date:** [December 30, 2016, 3:32pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/1 "2016-12-30T15:32:18Z")

</div>

I want to detect if the host os connman has connected to a wifi AP.

I am using dbus, as reverse engineered from the resin-wifi-connect:

`DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host_run/dbus/system_bus_socket`  
`dbus-send --system --dest=net.connman --print-reply /net/connman/technology/wifi net.connman.Technology.GetProperties`

but i’m getting the reply:

`Error org.freedesktop.DBus.Error.ServiceUnknown: The name net.connman was not provided by any .service files`

Any ideas?

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [December 30, 2016, 4:25pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/2 "2016-12-30T16:25:23Z")

</div>

Which device and which host OS version are you using? Connman is on the resinOS 1.x series, while resinOS 2.x has NetworkManager. I’m guessing you are using the latter, that’s why the issue you experience.

Just tried your version of the request on a Raspberry Pi 3 with host OS 1.24.1 (which uses Connman), and the result I get is:

```xml
method return sender=:1.3 -> dest=:1.10 reply_serial=2
   array [
      dict entry(
         string "Name"
         variant string "WiFi"
      )
      dict entry(
         string "Type"
         variant string "wifi"
      )
      dict entry(
         string "Powered"
         variant boolean true
      )
      dict entry(
         string "Connected"
         variant boolean true
      )
      dict entry(
         string "Tethering"
         variant boolean false
      )
   ]

```

Also tried on the 2.x line, which needs some NetworkManager magic:

Put together from the [NetworkManager DBus reference](https://developer.gnome.org/NetworkManager/unstable/spec.html) and this blogpost: [Dbus Tutorial - Fun with Network Manager](http://cheesehead-techblog.blogspot.co.uk/2012/09/dbus-tutorial-fun-with-network-manager.html), it should work with something like:

```bash
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
dbus-send \
 --system \
 --print-reply \
 --dest=org.freedesktop.NetworkManager \
 /org/freedesktop/NetworkManager \
 org.freedesktop.DBus.Properties.GetAll \
 string:"org.freedesktop.NetworkManager"

```

and look for the `State` variable, or call it directly with

```bash
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
dbus-send \
 --system \
 --print-reply \
 --dest=org.freedesktop.NetworkManager \
 /org/freedesktop/NetworkManager \
 org.freedesktop.DBus.Properties.Get \
 string:"org.freedesktop.NetworkManager" \
 string:"State"

```

`State` can take [these values](https://developer.gnome.org/NetworkManager/unstable/nm-dbus-types.html#NMState), and value `70` meaning global connectivity.

NetworkManager should have a lot more tricks up its sleeve, so would love to hear what you make in the end!

There’s also some notes in this other forum post [how to use Node.js with DBus for networking](https://forums.balena.io/t/raspberry-pi-3-and-additional-network-dongle/438/8), and there’s of course binding in a bunch of other languages to make it easier to tie it in.

---

<div class="post-metadata">

**Author:** ![keithejc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/keithejc/32/141_2.png) [@keithejc](https://forums.balena.io/u/keithejc)\
**Post date:** [December 30, 2016, 4:52pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/3 "2016-12-30T16:52:20Z")

</div>

I’m using Resin OS 1.19.0 and beaglebone-debian:jessie-20161228

weird.

although I wasn’t aware you were changing to networkmanager on 2.xx so I guess i’ll upgrade and try again using that…

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [December 30, 2016, 4:58pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/4 "2016-12-30T16:58:48Z")

</div>

For clarity, which BeagleBone are you using? Judging by the base image, you use BeagleBone Black, which only has Ethernet by default. If that one, how do you add a wifi interface to it?

---

<div class="post-metadata">

**Author:** ![keithejc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/keithejc/32/141_2.png) [@keithejc](https://forums.balena.io/u/keithejc)\
**Post date:** [December 30, 2016, 5:16pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/5 "2016-12-30T17:16:20Z")

</div>

Beaglebone Black

Using this cape:

[http://www.each-cs.com/ENG/internet\_hub.html](http://www.each-cs.com/ENG/internet_hub.html)

Works great - I currently drop .service files into `/host/var/lib/connman`. I guess Networkmanager works similarly?

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [December 30, 2016, 6:05pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/6 "2016-12-30T18:05:45Z")

</div>

I’ve just tried the currently downloadable resinOS 1.24 for the BeagleBone Black with a [Raspberry Pi wifi dongle](https://www.raspberrypi.org/products/usb-wifi-dongle/) and the command you mentioned work just fine, with this result:

```auto
root@beaglebone-1b16c8c:/# DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket dbus-send --system --dest=net.connman --print-reply /net/connman/technology/wifi net.connman.Technology.GetProperties
method return sender=:1.4 -> dest=:1.11 reply_serial=2
   array [
      dict entry(
         string "Name"
         variant string "WiFi"
      )
      dict entry(
         string "Type"
         variant string "wifi"
      )
      dict entry(
         string "Powered"
         variant boolean true
      )
      dict entry(
         string "Connected"
         variant boolean true
      )
      dict entry(
         string "Tethering"
         variant boolean false
      )
   ]

```

Is it possible for you to reflash the device with the latest resinOS and try again? It’s recommended to upgrade from 1.19 anyways.

x x x

On your later question, NetworkManager is somewhat different, so might need to modify how you are doing things. In resinOS 2.x you can set up connections by adding config files to the `resin-boot` partition’s `system-connections` directory (an example is included there all the time), and the DBus calls are different as mentioned above.

If you want to test 2.x, it’s available from [resinstaging](https://dashboard.resinstaging.io), our staging service which runs the latest beta services and images. You have to sign up there separately, and things are not expected to always work on staging (as opposted to the main production service)

---

<div class="post-metadata">

**Author:** ![keithejc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/keithejc/32/141_2.png) [@keithejc](https://forums.balena.io/u/keithejc)\
**Post date:** [January 19, 2017, 5:22pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/7 "2017-01-19T17:22:13Z")

</div>

For anyone that’s interested - I resolved the problem by issuing the commands all on one line:

`DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host_run/dbus/system_bus_socket dbus-send --system --dest=net.connman --print-reply /net/connman/technology/wifi net.connman.Technology.GetProperties`

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [January 19, 2017, 6:40pm UTC](https://forums.balena.io/t/detect-if-wifi-is-connected/473/8 "2017-01-19T18:40:55Z")

</div>

Yes, indeed that’s a single command for `dbus-send` with an environment variable (`DBUS_SYSTEM_BUS_ADDRESS`). Maybe have to clarify somehow, that it is how it works in the Linux shell, there’s no line break after the env var (these docs and forums break the lines, that’s why I prefer putting code in with the tripple-tick as a code block, rather than single tick as inline code (see the [Markdown Cheat Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting). Probably that’s what I’ve missed in your original comment too?

You can also do, by the way setting that env var with [export](http://ss64.com/bash/export.html):

```auto
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

```

and then all the following commands in that shell will be passed that parameters, so you can just run `dbus-send ...`
