Skip to content

Issues reconnecting to Wi-Fi after the link drops #72

Description

@laurento

Now that I can finally play with tinygo on my ESP32 boards (many thanks!) I'm trying to port some of my projects to it. However, I quickly ran into issues with my wi-fi routine because I couldn't find a way to create one that reconnects to the AP automatically when the link drops (e.g. noise, signal drop).

In fact, using something like the following excerpt is not going to work because when NetConnect() is called, a second time, after the link drops I receive an error about the fact that radio is already enabled.

for {
		println("[Wi-Fi] Connecting...")
		err := espLink.NetConnect(&netlink.ConnectParams{
			Ssid:       wifiSSID,
			Passphrase: wifiPass,
		})

		if err != nil {
			fmt.Printf("[Wi-Fi] Connect failed: %v\n", err)
		} else {
			println("[Wi-Fi] Connected successfully!")

			ip, _ := espLink.Addr()
			println(ip.String())
		}

		for {
			ip, err := espLink.Addr()
			if err != nil || ip.IsUnspecified() {
				println("[Wi-Fi] Disconnected or lost IP.")
				//espLink.NetDisconnect()
				time.Sleep(3 * time.Second)
				break
			}

			time.Sleep(5 * time.Second)
		}
	}

Moreover, looking at the code I noticed that NetDisconnet() is currently a no-op, and simply rebooting the board is not an option because other routines can keep doing their job just fine when offline.

Am I missing something? Do you have any suggestions?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions