B4R Question ESP8266 fast WiFi re-connection

peacemaker

Expert
Licensed User
HI, All

Anyone tried to use this https://www.instructables.com/ESP8266-Pro-Tips/ ?
To save the battery charge - make WiFi usage maximally fast.
My tests with 10 seconds of DeepSleep get 22...23 seconds of the whole loop, so WiFi re-connection is about 10 seconds (2-3 secs for others) - it's very loooong.
What is your results ?

Trying to use static IP settings (WiFi.config)- seems, stops WiFi connecting at all... When this should be implementeed - before Wifi.Connect ?
 
Last edited:

peacemaker

Expert
Licensed User
Hi, All

I have prepared the template sketch for creation the fast WiFi re-connection.

B4X:
LiveCounter = 94
Device_ID = F4CFA24CAFC7
InternetConnected = 0
Slow connecting to: pmaker.biz
InternetConnected = 1
WiFi connected: pmaker.biz; my ip: 192.168.1.116
Subnet Mask: 255.255.255.0
Gateway: 192.168.1.1
Settings saved.
Wifi, %: 100

It uses the libs:
1603806248890.png


Please, help to make fast WiFi re-connection - here is detailed code: https://pokewithastick.net/esp8266-fast-wifi-connect-post, but i cannot get to work - " WiFi.config(IPA, GATE, MASK); " does not help
 

Attachments

  • ESP_fastWIFI_v.0.01.zip
    5.1 KB · Views: 118
Upvote 0

peacemaker

Expert
Licensed User
The original Arduino's sketch is working !
B4X:
.......WiFi connected and credentials saved

HTTP server started
Connected to pmaker.biz
IP address: 192.168.1.116

snapshots of millis() counter..
Sketch begins: 64
WiFi connected: 9523
Network transaction completed: 14659

-------second re-connect---------------------

HTTP server started
Connected to pmaker.biz
IP address: 192.168.1.116

snapshots of millis() counter..
Sketch begins: 66
WiFi connected: 230
Network transaction completed: 5363

Initial connection was almost 9 seconds, second reconnect with the saved SSID, password (and static IP, gateway, mask) was ... 0.17 second !!!
It is the must to implement this with B4R - it's working on C! :)
 

Attachments

  • ESP_FastConnect_ARDUINO.zip
    4 KB · Views: 169
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Seems, working :)
1603891722341.png


But ... such fast reconnection is working only if to make restart ... manually.
If to use DeepSleep or just restart - fast connection stopped to work, again slow connection...
 
Upvote 0

peacemaker

Expert
Licensed User
Yesss ! ESP8266 DeepSleeps and at restart fastly re-connected to WiFi !
Project is attached - please, fix & update, and publish here.

B4X:
Private Sub ConnectToNetwork
    Dim b(4) As Byte = GlobalStore.Slot1
    If b(0) = 192 And b(1) = 168 Then
        Log("Fast WiFi re-connection try...")
        Dim mask(4) As Byte = GlobalStore.Slot2    'Array As Byte(255, 255, 255, 0)
        Dim gateway(4) As Byte = GlobalStore.Slot3    'Array As Byte(192, 168, 1, 1)
        Dim dns(4) As Byte = GlobalStore.Slot4 'Array As Byte(192, 168, 1, 1)
        others.ESPex.ConfigNetwork(b, gateway, mask, dns, dns)
    End If
    Dim counter As UInt
    Do Until counter > 1000
        others.Get_WiFiStatus
        If others.Wifistatus = 3 Then    'Connected !
            Exit
        End If
        Delay(5)
        counter = counter + 1
    Loop
    Log("Fast reconnection counter = ", (counter * 5) , " ms")
    Log("others.WiFistatus = ", others.Wifistatus)
    If others.Wifistatus = 3 Then    'wifi connected
        others.Check_Internet
    End If
    If counter > 1000 Then
        launchSlowConnect
    End If
   
    GlobalStore.Put(0, others.ESPex.SSID)
    Dim ip(4) As Byte
    others.ESPex.GetLocalIP(ip)
    GlobalStore.Put(1, ip)
    Log("WiFi connected: " , others.ESPex.SSID, "; my ip: ", others.ESPex.IP2str(ip))
   
    others.ESPex.GetSubnetMask(ip)
    GlobalStore.Put(2, ip)
    Log("Subnet Mask: ", others.ESPex.IP2str(ip))
   
    others.ESPex.GetGatwayIP(ip)
    GlobalStore.Put(3, ip)    'gateway
    GlobalStore.Put(4, ip)    'DNS
    Log("Gateway: ", others.ESPex.IP2str(ip))
   
       
    others.Save_Settings
    Log("Wifi, %: ", others.Get_WiFI_RSSI)
    If others.Wifistatus = 3 Then    'wifi connected
        others.Check_Internet
    End If
    Log("TODO: HTTP requests before DeepSleep...")
    others.Go_Sleep(10000)
End Sub

Sub launchSlowConnect
    others.SetupWiFi
    Log("Slow connecting to: ", others.SSID)
    wifi.Connect2(others.SSID, others.Password)
    Dim counter2 As UInt
    Do Until counter2 > 20
        others.Get_WiFiStatus
        If others.Wifistatus = 3 Then    'Connected !
            Exit
        End If
        Delay(500)
        counter2 = counter2 + 1
    Loop
    Log("Slow connection counter = ", (counter2 * 500) , " ms")
    If counter2 > 20 Then
        Log("Slow Wifi connecting is timed-out. Rebooting...")
        Delay(10)
        others.ESP.Restart
        Return
    End If
    Log("WiFi connected and credentials saved")
    Log("others.Wifistatus = ", others.Wifistatus)
    others.Check_Internet
End Sub
 

Attachments

  • ESP_fastWIFI_v.0.06.zip
    5.6 KB · Views: 132
Upvote 0

peacemaker

Expert
Licensed User
But battery economy result of such fast WiFi re-connection is not so good.
1) It was active 12 sec and 10 sec for DeepSleep: server had records each 22...23 seconds (between timestamps).
2) Now it's visually active 4 secs maximum for the same tasks (sensor data + HTTP requests) and 12 seconds of DeepSleep: server have records each 18...20 seconds.
Seems, should be 3 times better power consumption, i'll measure.
But not so high difference how expected...
 
Upvote 0
Top