The connman application provides an Erlang binding for the connman
connection manager.
- Get current available services
- Connect to an SSID by name instead of Service ID
- Notifications on connectivity state changes.
Add ebus-connman to your deps section in rebar.config:
{deps, [connman]}.To ensure that connman is tarted when your application starts also add
it to the applications section in your application's .app.src
file. For example:
{application, my_app,
[{description, "An application using connman"},
{vsn, "git"},
{registered, []},
{applications,
[kernel,
stdlib,
connman
]},
{env,[]}
]}.
Here's an example of talking to connman to get the current list of connectivity related technologies:
Eshell V10.1 (abort with ^G)E
1> {ok, C} = connman:connman()
{ok,<0.221.0>}
2> connman:services(C).
{ok,[{"/net/connman/service/wifi_a0c589a1baee_425452205570706572204150_managed_psk",
#{"AutoConnect" => true,
"Domains" => ["Home"],
"Domains.Configuration" => [],
"Ethernet" =>
#{"Address" => "A0:C5:89:A1:BA:EE","Interface" => "wlp2s0",
"MTU" => 1500,"Method" => "auto"},
"Favorite" => true,
"IPv4" =>
#{"Address" => "192.168.2.60","Gateway" => "192.168.2.1",
"Method" => "dhcp","Netmask" => "255.255.255.0"},
"IPv4.Configuration" => #{"Method" => "dhcp"},
"IPv6" => #{},
"IPv6.Configuration" =>
#{"Method" => "auto","Privacy" => "disabled"},
"Immutable" => false,"Name" => "BTR Upper AP",
"Nameservers" => ["192.168.2.1"],
"Nameservers.Configuration" => [],"Provider" => #{},
"Proxy" => #{"Method" => "direct"},
"Proxy.Configuration" => #{},
"Security" => ["psk"],
"State" => "online","Strength" => 58,
"Timeservers" => ["192.168.2.1"],
"Timeservers.Configuration" => [],"Type" => "wifi",
"mDNS" => false,"mDNS.Configuration" => false}}]}To get notified when connectivity of the system changes, call
register_state_notify. As an example:
Eshell V10.1 (abort with ^G)E
1> {ok, C} = connman:connman()
{ok,<0.221.0>}
2> connman:register_state_notify(self()).
okNow when the state of the network changes, the given handler pid will receive a message:
10> flush().
{state_changed, online}The values for state are the atom versions of the connman connectivity
names: offline, idle, ready, online. Refer to the connman
documentation for the latestdocumentation on the meaning of the state
names.
As an extension of normal connman behavior the API allows connecting
to an SSID by name and given a password will block until the
connection is established or fails. connman will try to find the
given SSID and will attempt to connect to it.
Eshell V10.1 (abort with ^G)E
1> {ok, C} = connman:connman().
{ok,<0.257.0>}
2> connman:connect(C, wifi, "My Access Point", "My AP Password").
okFork the repo and simply use make to build the library.