My conf file looks like this:
ssid="oldssid"
psk="oldpassword"
I'm using the following code to try and edit my Wifi settings in a Node JS app but it isn't making any changes to the file. Any advice would be much appreciated!
var ssid_command = "sed -i \'s/ssid=\"oldssid\"/ssid=\"" + newssid + "\"/\' /etc/wpa_supplicant/wpa_supplicant.conf";
var psk_command = "sed -i \'s/psk=\"oldpassword\"/psk=\"" + newpassword + "\"/\' /etc/wpa_supplicant/wpa_supplicant.conf";
require('child_process').exec(ssid_command, function (msg) { console.log(msg) });
require('child_process').exec(psk_command, function (msg) { console.log(msg) });
Turns out all I had to do was add sudo
to the beginning so that I have permission to edit the file.