Skip to content

Instantly share code, notes, and snippets.

@sabas1080
Created July 17, 2019 18:11
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 sabas1080/93823a5d653411e8bb890122aafd0d43 to your computer and use it in GitHub Desktop.
Save sabas1080/93823a5d653411e8bb890122aafd0d43 to your computer and use it in GitHub Desktop.
interface Secrets {
connString: string;
wifi: StringMap;
}
// this is to be overridden in a separate file
let secrets: Secrets;
function test() {
const log = console.log;
const esp = new esp32spi.SPIController(pins.spi(),
pins.D13, pins.D11, pins.D12, pins.D10, 1)
if (esp.status != esp32spi.WL_IDLE_STATUS)
return
log(`Firmware vers. ${esp.firmwareVersion}`)
log(`MAC addr: ${esp.MACaddress.toHex()}`)
log("Temp: " + esp.getTemperature())
const networks = esp.scanNetworks()
log(JSON.stringify(secrets.wifi))
for (const ap of networks)
log(`\t${ap.ssid}\t\tRSSI: ${ap.rssi}`)
for (let k of Object.keys(secrets.wifi)) {
if (networks.some(n => n.ssid == k)) {
log("connecting to " + k)
esp.connectAP(k, secrets.wifi[k])
break
}
}
if (!esp.isConnected) {
log("can't connect")
return
}
log("ping: " + esp.ping("bing.com"))
}
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment