mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-20 14:39:00 +00:00
examples/wifinina: improve connectToAP() and other needed minor corrections
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -56,6 +56,7 @@ func main() {
|
||||
adaptor.Configure()
|
||||
|
||||
connectToAP()
|
||||
displayIP()
|
||||
|
||||
for {
|
||||
sendBatch()
|
||||
@@ -111,29 +112,42 @@ func sendBatch() {
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
func displayIP() {
|
||||
ip, _, _, err := adaptor.GetIP()
|
||||
for ; err != nil; ip, _, _, err = adaptor.GetIP() {
|
||||
message(err.Error())
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
message(ip.String())
|
||||
message("IP address: " + ip.String())
|
||||
}
|
||||
|
||||
func message(msg string) {
|
||||
println(msg, "\r")
|
||||
}
|
||||
|
||||
func failMessage(msg string) {
|
||||
for {
|
||||
println(msg)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user