Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created November 23, 2016 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlingineni/3b3863c06543533eacac076071ea8074 to your computer and use it in GitHub Desktop.
Save rlingineni/3b3863c06543533eacac076071ea8074 to your computer and use it in GitHub Desktop.
Raspberry Pi Wifi Config update function
console.log("Updating Wifi to SSD: " + SSID);
var data = fs.readFileSync('/etc/wpa_supplicant/wpa_supplicant.conf', 'utf8');
var result = data.replace(/ssid="(.*)"/g, 'ssid="'+ SSID + '"');
var finalResult = result.replace(/psk="(.*)"/g, 'psk="'+ Password + '"');
console.log("Will print: \n" + finalResult); //this prints out correctly, finalResult holds what I want it ot
//need to fix writing to file (only writes like a piece of it)
fs.writeFile('/etc/wpa_supplicant/wpa_supplicant.conf', finalResult, 'utf8', function (err) {
if (err) return console.log(err);
console.log("about to reboot network config");
//rebootNetwork();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment