terraspace
Posts: 76
Joined: Mon Dec 03, 2018 3:56 pm

Wifi control from C/C++

Mon Dec 03, 2018 4:00 pm

Hi,

I found a sample using libiw to perform a wifi ap scan which seems to be working, however I have a few different requirements which I need to be able to complete programmatically from C/C++:

1) Enable/Disable WIFI
2) Scan for available AP's
3) Connect and Disconnect from particular AP (including supplying password / key if required)
4) Create and Destroy an AD-HOC wireless network for clients to connect to in the absence of existing wi-fi.

I've had a look at various suggestions around d-bus, network manager(which doesn't seem to be the default on the pi) and this lib-iw which isn't really well documented.

Any help or pointers in the right direction on how to achieve the above from C would be greatly appreciated!
Thanks
John

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Wifi control from C/C++

Tue Dec 04, 2018 10:31 pm

If you figure how to do it from C/C++ let everyone know.

Most of us need to use library calls inside of an operating system that supports the Hardware and releated protocalls, there are precious few that know how to do this directly from C, which would mean running on baremetal.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

ElEscalador
Posts: 734
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Wifi control from C/C++

Wed Dec 05, 2018 1:58 am

Closest I've done is system() calls to sudo ifdown or ifup for turning the wifi on or off...as well as the ethernet connection and the wifi hotspot (which could function as ad-hoc connection when no internet was present). So I've done it with c but not really with c, if you know what I mean - I wasn't looking for fancy, just to control my kids internet access. It should also be trivial to modify /etc/wpa_supplicant/wpa_supplicant.conf where wifi points and passwords are stored as simple if you know how to read and write from files. Just delete all but the one you want to specifically connect to.
Giving away some sensors and robot parts in advance of my book release! The first review and giveaway below!

https://youtu.be/fCX0HaeQiyw

User avatar
DerKleinePunk
Posts: 73
Joined: Thu Feb 23, 2017 9:18 am
Location: Germany
Contact: Website

Re: Wifi control from C/C++

Mon Dec 31, 2018 7:42 am

PI 2 und PI 3 1GB Raspbian Strech
Der Wandel von Atom zum Bit ist unwiderruflich und nicht mehr aufzuhalten.
Nicholas Negroponte

Return to “C/C++”