Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
configure wpa_supplicant.conf
#include "ofMain.h"
#include "ofAppNoWindow.h"
#define WPA_PATH "/etc/wpa_supplicant/wpa_supplicant.conf"
class ofApp : public ofBaseApp
{
public:
string essid;
string passwd;
ofApp(string _e, string _p){
essid = _e;
passwd = _p;
}
vector<string> getESSID()
{
vector<string> r;
string out = ofSystem("/sbin/iwlist wlan0 scan | /bin/grep ESSID");
vector<string> split = ofSplitString( out,"\n" );
for( int i = 0; i < split.size(); i++ )
{
string s = split[i];
ofStringReplace(s,"ESSID:","");
if(s!="")
{
ofLog()<<s;
r.push_back(s);
}
}
return r;
}
void setup()
{
string conf_wpa = "network={\n";
conf_wpa+= "\tssid=\""+essid+"\"\n";
conf_wpa+= "\tpsk=\""+passwd+"\"\n";
conf_wpa+= "}";
cout<<conf_wpa<<"\n";
ofBuffer buf(conf_wpa.c_str(),conf_wpa.size());
if( ofBufferToFile("tmp.config", buf) ){
ofFile file("tmp.config");
if( file.copyTo(WPA_PATH) ){
ofLog()<<"Success copy configuration in:"<<WPA_PATH;
}
}
else{
ofLog()<<"Error!";
}
ofExit(1);
}
};
int main(int argc, char** argv)
{
if(argc<3)
{
ofLog()<<"Error argument: essid passwd";
exit(0);
}
string e(argv[1]);
string p(argv[2]);
ofAppNoWindow w;
ofSetupOpenGL(&w, 0,0, OF_WINDOW);
ofRunApp( new ofApp(e,p));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.