-1

I need connect headless IoT device (Raspberry Pi) to Wi-Fi Network. I have custom Linux built using YoctoProject. I don't have connman or Network Manager installed. There is only WPA Supplicant. My services are written in Golang.

Call wpa_cli is too tricky and not reliable. Trying few available packages, I have decided to write my own. See below in answer.

Mark Berner
  • 119
  • 1
  • 6
  • Can you create a rest api using this? I want to run a Rest API on PI so that I can change and get all the available Wifi's inside a client. – Bharat Chhabra Jan 31 '20 at 05:36

1 Answers1

2

Answering to my own question...

wpa-connect - API for connection Linux device to Wi-Fi Network (Golang)

This package was developed as part of IoT project in order to add Wi-Fi connectivity to headless Raspberry Pi like devices. No need to connman or Network Manager be installed. wpa-connect communicates with WPA supplicant over D-Bus (linux message bus system).

Github repository https://github.com/mark2b/wpa-connect

Examples Connect to Wi-Fi network

import wifi "github.com/mark2b/wpa-connect"

if conn, err := wifi.ConnectManager.Connect(ssid, password, time.Second * 60); err == nil {
    fmt.Println("Connected", conn.NetInterface, conn.SSID, conn.IP4.String(), conn.IP6.String())
} else {
    fmt.Println(err)
}

Scan for Wi-Fi networks

import wifi "github.com/mark2b/wpa-connect"

if bssList, err := wifi.ScanManager.Scan(); err == nil {
    for _, bss := range bssList {
        print(bss.SSID, bss.Signal, bss.KeyMgmt)
    }
}

Package released under a MIT license.

Mark Berner
  • 119
  • 1
  • 6
  • 4
    This is not a place for advertising your own code (even though it might be useful), especially not as an answer to your own question and without any mentioning that this is your code. – Steffen Ullrich Sep 02 '18 at 19:19