B4R Question ESP8266 hang

peacemaker

Expert
Licensed User
Hi, All

Who trapped such hangs ? How to track, debug ?

My situation is so: ESP8266 is used for sensor reading via RS485. Now cable is long, 30 meters, testing stage.
3 kinds of HTTP-requests to a server:
  • sending sensor data each 1 hour (settable from a server by a command)
  • sending a status each 3 mins
  • checking for new commands to execute (change settings or report the configurations = all settings) - each 15 seconds.
No sleep is used, but each 1 minute - the software restart. Minutes counter (with saving to RTC memory), checking the time intervals by means these minutes counter.
It is working for hours, log of the HTTP-requests shows the correct queue of requests, but sometimes only "command" requests are in the log only, 2 other HTTP-requests disappeared at all.
And after some minutes - nothing.

Now i have trapped this situation, connected by USB cable to a COM-port, ....and nothing from port. Looks like full hang. Power restart solved the situation - B4R log from port has started to show.
---------------
Any experience ? How to debug ?
 

peacemaker

Expert
Licensed User
But how can it be, if the 1 min software reset timer is always on, never stopped ?
And now found that during hanging, if to plug the USB cable and re-compile and re-flash the ESP - it's started OK, with log as usual, without power re-plugging.
But why not restarted by a timer for sure ?
 
Upvote 0

janderkan

Active Member
Licensed User
Are you aware of the little flaw in B4R ?
if you are using timer events you must write to the log each time.
B4X:
Log(" ")
If not the timer will stop firing events after some time. The time between failure is not the same.

To make it easier to debug I only do it in production mode.
B4X:
#If PROD
    Log(" ")
#End if
 
Upvote 0

peacemaker

Expert
Licensed User
I will try, thanks !
I guess, any string can be logged, not only " " ?

And my 1min restart timer had and has Log() call - and it's not restarted for sure.
But the timer where 2 http-requests are called - yes, without Log(). Added, testing.
 
Last edited:
Upvote 0

candide

Active Member
Licensed User
one thing can block a B4R code without reset, an array issue.
in log file you have : Out of bounds error.Array length = 60, Index = 65535
and it stops...
 
Upvote 0

peacemaker

Expert
Licensed User
Never seen such out of bounds error.
My latest test with Log() in timer sub did not help during latest hours.
Now changed 1 min timer sub, removed all conditions, for restart with minimal conditions.

B4X:
Private Sub timWatchDog_Tick
    Log("WatchDog !")
    If others.isConnected Then
    Else    'no internet
        Log("WatchDog: No Internet - resetting WiFi")
        others.ResetWiFi
    End If
    'If webapi.GettingCommand = True Or HttpJob.WorkingFlag Or sensor.ReadingFlag Then    'if working - then later
    If sensor.ReadingFlag Then    'if working - then later
        CallSubPlus("Restart_Delayed", 2000, 7)   '7th point of restart
    Else
        others.restart(2)
    End If
End Sub

Private Sub Restart_Delayed(tag As Byte)
    others.restart(tag)
End Sub
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Seems, solved. And as usual the trouble root is not in B4R, but in just my code, conditions :)
After latest changes in timer event - all works OK :)


NO ! After 28 hours it hungs ! Nothing from log, nothing to server...
And many forums are with such hung, a better power filtering is required, will try.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Hung was once per 24...30 hours only. I was checking the power supply also.
Before it was hanging with #StackBufferSize: 1000.
Now 1300.
 
Upvote 0
Top