B4R Question MY ESP32 IS GETTING WIFI OFFLINE AFTER 5 HOURS

NOUSHAD OLAKARA

New Member
I AM USUNG ESPA ALEXA CODE FOR WIFI SWITCH EVERYTHING WORKS FINE EXCEPT MY ESP32 IS GETTING WIFI OFFLINE AFTER 5 HOURS
I WANT ESP32 KEEP ALIVE IN WIFI ,WANT TO REMOVE STAND BY MODE
I WAS TRIED THIS NOT ABLE TO COMPILE ANY ONE CAN HELP ME PLEASE FOR THIS TO SOLVE
#if C
#include <esp_wifi.h>
void SetWifi (B4R::Object* o) {
esp_wifi_set_ps(WIFI_PS_NONE);
}
#End if


ATTACHED ZIP FILES

THERE IS ERROR I WAS ATTACHED
 

Attachments

  • for 4x upload.zip
    69.5 KB · Views: 221

KMatle

Expert
Licensed User
Longtime User
Welcome to the forum. Please don't use capital letters as it means "shouting".

Create a timer and check if it helps (so the ESP is busy). If not ping a website (e.g. Google) every 10 mins. or so with OkHttpUtils which keeps the WiFi alive.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I add to @KMatle comment that, when posting code, please use the code tags. It will help make it more readable.
 
Upvote 0

NOUSHAD OLAKARA

New Member
Welcome to the forum. Please don't use capital letters as it means "shouting".

Create a timer and check if it helps (so the ESP is busy). If not ping a website (e.g. Google) every 10 mins. or so with OkHttpUtils which keeps the WiFi alive.

can you please explain me clearly how to do that ,i have uploaded my detailed files
if you support me and if successful means ofcourse i can support you
thank you
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Just define a timer in Globals and let it "tick"

B4X:
Private Timer1 As Timer

B4X:
Timer1.Initialize("Timer1_Tick", 10000)
Timer1.Enabled = True

B4X:
Private Sub Timer1_Tick
    log("Tick...")
End Sub

This should keep the ESP32 busy and prevent it from going to sleep.

If this doesn't help, check if WiFi is connected in the Inline C section -> call a function from B4R from the timer's sub and use WiFi.status() and re-connect. Search the WWW for examples.
 
Upvote 0

NOUSHAD OLAKARA

New Member
Use the search function in this forum, e.g. esp32 Alexa or esp8266 Alexa.
When writing a post look to the header to see the formatting/insert function.
Where is your B4R code ? There is only Arduino Code in the ZIP File.

First of all read the basic's before you start.

Thank you dear your information
i just see some of the videos b4x basic then i found ,in my system arduino.exe not installed ,it was working as program directly, for R4R need the arduino.exe in program files, any way i got little because of your information
thank you
 
Upvote 0

NOUSHAD OLAKARA

New Member
Just define a timer in Globals and let it "tick"

B4X:
Private Timer1 As Timer

B4X:
Timer1.Initialize("Timer1_Tick", 10000)
Timer1.Enabled = True

B4X:
Private Sub Timer1_Tick
    log("Tick...")
End Sub

This should keep the ESP32 busy and prevent it from going to sleep.

If this doesn't help, check if WiFi is connected in the Inline C section -> call a function from B4R from the timer's sub and use WiFi.status() and re-connect. Search the WWW for examples.
finally i have uploaded in B4X (R4R) zipp file you can see download that to check what is wrong on it please
 

Attachments

  • test r4x esp timer to upload.zip
    2.3 KB · Views: 220
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Your code is all jumbled up - this is how a B4R program should look

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src


' this part is for B4R code only no C code allowed

Sub Process_Globals
    Public Serial1 As Serial
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    ' do all the things you want in B4R code
End Sub

' end of B4R code area


' Start of the C code area
#if C

// put all the C code here between If C and End If

#End If
' end of the C code area
 
Last edited:
Upvote 0

Laurent95

Active Member
Licensed User
Longtime User
Hi,

@ NOUSHAD OLAKARA :
Your code is all jumbled up - this is how a B4R program should look
I will say more than Daestrum: But Why you use B4R ? In your example it would be better to do that under Arduino's IDE and it would be more readable and debuggable ! There is no B4R code !
And also:
Try to understand how the ESP32 works too. It's a dual core and it's, at 1st, a Wifi and Bluetooth plateform who need bit time to do his Wifi or Bluetooth management in background.
It's never good to think and did like with other µControleur like the Arduino, etc.who are dedicated to manage nothing else than his analog and digital IO. and a bit of cycles for registers, timers and interrupt but nothing behind.
On all ESP, but especially on the 32 who do that on the 2nd core, t's imperative to let time to this 2nd core to manage Wifi and services associated.
Start to understand these limitations before use them, and you'll avoid a lot of issues.
If the primary core is too busy it will sometime make Wifi stop or crash.
So in your example code even if it' would under Arduino's IDE all the 'delay' in the 'loop' are blocking.
The µC can't do anything else than waiting. Very bad approche to start !
And with your code you can be sure that B4R could never help you in this case.

Generally on an ESP, more on an ESP32, you don't need to take care of Wifi if it's good configured.
If you don't have project powered under batteries you can even disable the sleep functions of ESP
It would seems you need to understand 1st the basis of how the µControler you try to use works.

Regards
 
Upvote 0
Top