Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active January 29, 2019 14:00
Show Gist options
  • Save ElectricImpSampleCode/d7c10d1bd0c956d3d2eba6cd9f059d18 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/d7c10d1bd0c956d3d2eba6cd9f059d18 to your computer and use it in GitHub Desktop.
Electric imp imp API imp.getwifihints() example
// Post-reconnection attempt handler
function reconnect(reason) {
if (reason != SERVER_CONNECTED) {
// Reconnection failed, so re-attempt in 1 minute
imp.wakeup(60, function() {
server.connect(reconnect, 30);
});
}
}
// Force the imp to connect at 2.4GHz even if it previously connected via 5GHz
// Get the imp's current list of known base-stations
local hints = imp.net.getwifihints();
if (hints.channel > 13) {
server.log(format("Switching BSSID %s from channel %d to channel 1", hints.bssid, hints.channel));
// Stored 'preferred' channel is in the 5GHz band so change to channel 1
imp.net.setwifihints(hints.bssid, 1);
// Wait for impOS to idle then perform a disconnect/reconnect cycle
// in order to join the network with the specified BSSID
imp.onidle(function() {
server.flush(10);
server.disconnect();
server.connect(reconnect, 30);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment