Last active
November 12, 2016 13:32
-
-
Save kashimAstro/8b4a54b1cbc15fe7982096f256afbb5d to your computer and use it in GitHub Desktop.
configure wpa_supplicant.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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