What's your average time to connect to a Wifi in station mode with your

What’s your average time to connect to a Wifi in station mode with your esp8266?

I have been profiling my DHT22-based sensor node. Most of the time (~2s) is spent on connecting to the AP. Data acquisition itself takes around 275ms. Publishing the data (including the timing metrics) takes about 200ms as well.

What are your figures here? I already got it down from 4s to 2s by using a static IP.

Other things I have tried, which helped only marginally at best:

  • setting the BSSID and the channel
  • using Wifi.setAutoReconnect(true)

Most of these tips come from https://github.com/z2amiller/sensorboard/blob/master/PowerSaving.md

If you are curious, my current Arduino code is at https://github.com/mhaas/esp8266_sensor_node_code/blob/master/src/weather_station_mqtt.ino#L79 - still quite messy :slight_smile:

I suspect the AP is causing the delay. I use ESP-01s and the AT command set. Mine connect in a second or less. I haven’t measured it, though. From a terminal at 9600 baud, the connected response is almost immediate.

Bonus: my graph. http://i.imgur.com/fPLxtGG.png

The spikes around 7:30 are caused by me moving the node to the office for experimentation… I will be able to see if I actually made it worse this evening :slight_smile:

@Phillip_Landmeier Once the AT command returns - is the ESP actually connected or is it connecting asynchronously in the background?

@Michael_Haas No. Once you receive the “connected” string, it’s really connected to the AP. Then, in my case, I have to send more commands to put it into the mode I want so I can send and receive UDP packets.

Some helpful info here. Thanks.

I have read about this before, when you wake from deep sleep you do not need to reinitialise all of the wifi settings, if you do so you suffer a couple of seconds delay. One of the setup/status functions lets you know you can skip a load of the rest of it. sorry, i dont remember the detail beyond that, but hopefully it will help you find it.

@Justin_Mitchell It stores settings in NVM if you use the AT command to set it. My design cuts power completely to peripherals. Only the PIC remains powered. Using the presets speeds things up a lot. In fact, I set my esp-01’s to connect automatically on powerup and it happens very fast.

Thanks everyone for their input! I believe I am doing everything right - I use a static IP and the ESP is set to auto-connect on boot. I have disabled the explicit channel setting on start as I’m afraid that might slow things down (perhaps reset the connection?). Other than that, I have bumped up the sleep interval… it could be possible that the AP does not like repeated quick reconnects from the same source.

Anyways, with today’s settings (before the changes I just indicated), I am averaging 2s per cycle.

@Michael_Haas I don’t think 2 sec is that bad, really, given that WiFi wasn’t designed for that kind of thing.

I am not talking about the AT command firmware, but about writing for the bare hardware using the sdk or arduino environments. imho the using the AT firmware is a waste of an otherwise pretty powerful microcontroller, but anyway, found a bit more reference on the reconnect time after deep-sleep, it seems you should carefully check the results of WiFi.status() BEFORE doing a WiFiClient.connect() as doing that connect on an already connected device will give you a second or two penalty and may not be necessary

@Justin_Mitchell are you by any chance mixing up WiFiClient.connect() with Wifi.begin()? The former just opens a tcp connection I believe.

In any case my current (last night’s) setup did check if the saved SSID matched the desired SSID before initiating the connection.