B4R Question Errors handling on lost connection, client/ server tutorial, 8266 wifi

RJB

Active Member
Licensed User
continued from: https://b4x.com/android/forum/threads/error-log-in-b4r-astreams-client-server-tutorial.108554/
Erel had explained that with B4R Astreams, astream_Error is raised when the connection is broken.
Using the code from: https://www.b4x.com/android/forum/threads/connecting-two-esp8266-boards.89726/#content but with the server.Socket.Close statement removed:

I assumed that removing the .close statement would leave the connection in tact, which it does. But I also assumed that in that state removing the power from the device at one end would break the connection and produce an error at the other.
Removing the power at the server end does, indeed, produce an error at the client end.
But, removing the power at the client end doesn't give any error at the server end, even after many minutes. Further, on re-connecting the power at the client end, the client tries to connect and write and, apparently, succeeds but nothing happens at the server end.
 

Erel

Administrator
Staff member
Licensed User
The Error event will be raised when the device recognizes that the connection has broken. You can add send "ping" messages with a timer and close the connection if there is no response after X seconds.

The reason that this specific example closes the connection after the message is sent is exactly to solve such cases. Maintaining a connection is not simple. It is easier to create a new connection and close it when done.

In order to help you we need to know what are you doing with the connection. Maybe you should use a higher level solution such as MQTT.
 

RJB

Active Member
Licensed User
I am trying to send messages from many 8266s to a B4A server on a regular basis (at say 10 second intervals). I had three problems:
1) Trying to reduce power consumption, the use of DeepSleep can reduce this to a degree but problem 2) below means that it is almost impossible to battery power the 8266s.
2) the connection time of the 8266 to the router which can be over 10 seconds (even 20S on occasion!). I'm presuming that's outside of B4R's control, probably the router.
3) lost messages: I'm trying to localise the cause now. The 8266s are sending OK but I don't know yet whether the problem is in the transmission or some problem within my B4A code. I'll ask another question if I can't find the answer.

I'm presuming that the lower level transmission is reliable, i.e. if there is a connection then a message send should be safely received. Is that a safe assumption?

Thanks
 

RJB

Active Member
Licensed User
OK thanks, I'll give that a try.
I'll ask another question regarding safely adding data to a map in such situations.
 
Top