Could it be that in setConfig you're actually forcing a connect again, then saving?
In that case, it'd be saving the current state (which is in the middle of a connection), but then onInit is firing off a second connection?
Having said all that, saving the network details the way you're doing (re-saving all your code) isn't ideal. In 1v96 I added Storage module which allows you to save small amounts of data. For instance:
// update wifi details
function setConfig(name, password) {
require("Storage").write("wifi",{
name:name, password:password});
}
function onInit() {
var WIFI_NAME = "...";
var WIFI_OPTIONS = { password : ".." };
var wifiConfig = require("Storage").readJSON("wifi");
if (wifiConfig) {
WIFI_NAME = wifiConfig.name;
WIFI_OPTIONS = { password : wifiConfig.password };
}
console.log(WIFI_NAME,WIFI_OPTIONS);
wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
....
});
}
So now when you change your wifi details it modifies just the wifi details in a file called wifi, but leaves everything else the same (and doesn't require a reboot).
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
That's an odd one - just tried here with:
then:
And it seems to work...
Could it be that in
setConfig
you're actually forcing a connect again, then saving?In that case, it'd be saving the current state (which is in the middle of a connection), but then
onInit
is firing off a second connection?Having said all that, saving the network details the way you're doing (re-saving all your code) isn't ideal. In 1v96 I added
Storage
module which allows you to save small amounts of data. For instance:So now when you change your wifi details it modifies just the wifi details in a file called
wifi
, but leaves everything else the same (and doesn't require a reboot).