Connect to WiFi given SSID and password from the shell OR programmatically connect to a WiFi by writing a C program

Hello everyone,

I am tyring to find a way to connect my Banana Pi M5 to a WiFi knowing the SSID and the password a priori on boot.

Since the Banana Pi M5 does not have a wifi card I’m using a USB dongle and I possess a root shell on the device.

The only way I’ve found is to use wpa_cli and wpa_supplicant.conf but no matter my wpa_supplicant.conf I can’t seem to get it to connect. It just doesn’t with no errors displayed. Also it says that wpa_supplicant command is not found, even tho I have wpa_cli. Am I missing something? Is there another way?

I was considering writing a small standalone binary in C that programmatically connects to a given wifi but I don’t really know where to start as I haven’t found useful articles online, how could I achieve this behavior? I know how to compile for the right target, I’d just like some guidance on which libraries to look at.

Hopefully the questions are not too broad, I’ll be open to expand on the topics. Thanks

Use NetworkManager and nmcli?

@ericwoud Unfortunately there’s no nmcli command

/system/bin/sh: nmcli: not found

UPDATE: I’ve achieved it by writing an application that leverages the android.net.wifi.WifiManager with no UI and then starting it via am