Android Question ESP8266 UDP Receive

Nitin Joshi

Active Member
Licensed User
Hi, In my project, so far, i am successful in establishing UDP communication between B4A APP and ESP8266 via home router. ESP 8266 periodically (around every 300ms) sends "Hello" message to APP to inform that its alive. After few hours, around 10 to 12 (can not say exactly), I have observed that ESP8266 fails to receive messages from my APP however ESP8266's "Hello" messages are continued to receive by my APP - I confirmed its not APP issue because from i tried to send messages to ESP8266 via other UDP Monitor APP (available on Google play store) but same observation (ESP not receiving UDP packets).
My ESP is surely not getting hang as Hello messages are received successfully.
I request expert suggestion. Is there modification require in ESP8266 program or any other issue because when i restart my home router everything works fine (transmit/receive both from ESP to APP and vice versa).
ESP8266 is written in Arduino
APP is developed in B4A.
 

MicroDrie

Well-Known Member
Licensed User
The UDP protocol does not guarantee that a sent package has actually been received correctly by the receiving party (eq. It is a sessionless protocol). That the problem is resolved after restarting the router seems to be an indication that the problem may be caused by the router software.

Maybe you can use a solution based on the B4R Library WebSocketClient?
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Thanks for the feedback. I agree, UDP packets don't guarantee delivery but I am sure that this issue is not related to UDP packet guarantee related otherwise some packet may not had been delivered.
Is there any way to check out whether router is causing problem or not? Like for ping we use tracert...
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Thanks for the feedback. I agree, UDP packets don't guarantee delivery but I am sure that this issue is not related to UDP packet guarantee related otherwise some packet may not had been delivered.
Is there any way to check out whether router is causing problem or not? Like for ping we use tracert...

Both Ping and Trace route commands starts a new session for the router software. This offers no guarantee that this says anything about the UDP session of your application. You could see if the router has the latest software version and if not, upgrade it to the latest version. But this too is no guarantee for a solution for your problem.

I would opt for a web socket solution.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
If router is an issue then I will have problem for web socket also, isn't it?

The websocket protocol sets up a session of which:
  • the status of the connection can be read,
  • the connection can be disconnected within the protocol
That is simpler for the router and therefore less chance of problems.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
I had the same problem using B4A and B4R. Both UDP and 'sockets' gave the same problem.
MQTT using QOS 1 or 2 was recommended but the 8266 B4R client does not support anything other than QOS 0. So the only solution seems to be using a timer to retry if the message isn't confirmed as received.
Possibly the Arduino/ 8266 combination offers QOS 1/2?
 
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
HI
Why do you send a message from Esperanto 8266 every 300ms? Try increasing the time interval to 1000ms. Your router may be a problem here...
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
If it's the same issue I had then the repeat rate wouldn't be the problem, I was using 10seconds.
UDP/ 'sockets' would last less than 24hours. Without repeat sending MQTT lasts a few days.
In case it is to do with the router, mine is from TalkTalk.
 
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
It is difficult to advise when the code is not visible...What does your ESP8266? I made a device on Arduino ESP8266 that measures the temperature of four DS18B20 knots and sends the UDP results to the application Termik4temp.
Everything has been running continuously for two years on many phones and routers, no one reports any bugs.

The operation of this solution is very simple. The ESP8266 module listens to UDP packets on a specified port all the time and is practically idle. Only when the UDP packet from the Termik4Temp application with a control command arrives does it measure the temperature from DS sensors and sends the result back to the ip address from which the command was received. The application Thermk4temp sends this command every 2 seconds (when active).

Interestingly, it works on multiple phones at the same time.
 
Last edited:
Upvote 0
Top