Author Topic: What does WiFi.begin() do?  (Read 1776 times)

digi_guy

  • Jr. Member
  • **
  • Posts: 87
What does WiFi.begin() do?
« on: April 10, 2016, 03:46:53 pm »
It's a function that I find pooly documented both for Arduino and the Oak. When looking at online examples it is traditionally needed to get the Arduino wifi shields to work, but with the Oak a lot of that is built in. What I have noticed is that it wreaks havoc on my code.

When I watch the particle dashboard I'll see messages about "device came online" and "device went offline" repeated.

Ultimately I'd like to make sure that the Oak is connected before any other code runs, especially for situations where there might not be an internet connection.

Would I be better off using WiFi.status()?


PeterF

  • Hero Member
  • *****
  • Posts: 883
Re: What does WiFi.begin() do?
« Reply #1 on: April 10, 2016, 11:57:45 pm »
I'm not 100% sold yet on needing to worry about the connect / disconnect messages yet, as I think that is the particle connection / disconnection, not necessarily the device.

You may be better off using the Oak versions of those commands - I'm assuming they exist due to variances in how they work internally on the Oak as opposed to the official ESP8266 commands. Particularly Oak.connect(), Oak.connected() and Oak.waitForConnection(). You can see the full list here on the Oak wiki.

As far as what WiFi.begin() does, I don't think it is much more than basically putting the ESP8266/Oak into client mode, and then connecting to the configured access point. I think issue with particle saying connected / disconnected is more due to the wifi still trying to finish connecting, so it drops the particle connection for a moment. Other times, it is due to some bootup issue, so it keeps cycling.

You might be able to use WiFi.status(), but it looks like you would be better using Oak.waitForConnection() or Oak.connected(). Perhaps with some loop handling and some sort of timeout so it can go into a recovery mode or something.
« Last Edit: November 11, 2016, 10:08:54 pm by PeterF »