mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-22 23:49:02 +00:00
examples/wifinina: improve connectToAP() and other needed minor corrections
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -65,6 +65,7 @@ func main() {
|
||||
adaptor.Configure()
|
||||
|
||||
connectToAP()
|
||||
displayIP()
|
||||
|
||||
opts := mqtt.NewClientOptions()
|
||||
opts.AddBroker(server).SetClientID("tinygo-client-" + randomString(10))
|
||||
@@ -101,26 +102,33 @@ func main() {
|
||||
println("Done.")
|
||||
}
|
||||
|
||||
const retriesBeforeFailure = 3
|
||||
|
||||
// connect to access point
|
||||
func connectToAP() {
|
||||
time.Sleep(2 * time.Second)
|
||||
println("Connecting to " + ssid)
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
if err != nil { // error connecting to AP
|
||||
for {
|
||||
println(err)
|
||||
time.Sleep(1 * time.Second)
|
||||
var err error
|
||||
for i := 0; i < retriesBeforeFailure; i++ {
|
||||
println("Connecting to " + ssid)
|
||||
err = adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
if err == nil {
|
||||
println("Connected.")
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
println("Connected.")
|
||||
// error connecting to AP
|
||||
failMessage(err.Error())
|
||||
}
|
||||
|
||||
func displayIP() {
|
||||
ip, _, _, err := adaptor.GetIP()
|
||||
for ; err != nil; ip, _, _, err = adaptor.GetIP() {
|
||||
println(err.Error())
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
println(ip.String())
|
||||
println("IP address: " + ip.String())
|
||||
}
|
||||
|
||||
// Returns an int >= min, < max
|
||||
|
||||
Reference in New Issue
Block a user