Reputation: 613
I am working on a esp8266 library for using a web enable device (mostly just phones) to control a robot. The user connects to a server running on the esp and the library uses WebSockets to send updates about buttons, joysticks, and/or anything else.
The problem is that the data starts getting delayed and sometimes message get received very late, because it uses TCP (it would work better if those messages just didn't get delivered). Also since the esp has low memory this can causes it to crash.
How would I optimize this to update as fast as possible without receiving old messages?
Would something like WebRTC be better or is there something else more suited for this purpose? WebSockets using UDP seems like a better choice, but apparently browsers cannot send UDP?
What sort of stuff should look into/use?
By the way, if it helps, here is a link to my library.
Thanks for any help.
Upvotes: 3
Views: 1554
Reputation: 72
MQTT is a great protocol option when looking for rapid, lightweight messaging. I may be biased as a member of the HiveMQ team, but HiveMQ's cloud offering is a great free demonstration of what can be achieved with MQTT.
MQTT also offers quality of service levels that can be specified to ensure message delivery follows the pattern you are expecting - if for example a message needs to be delivered only once, that is an option.
If you happen to be interested in utilizing MQTT, there is even a getting started guide available specifically for ESP8266 devices.
https://www.hivemq.com/mqtt-cloud-broker/
Best,
Aaron from the HiveMQ Team
Upvotes: 0
Reputation: 41
I would suggest to use an MQTT as your communication protocol, try using HiveMQ on the cloud it's very easy and straight forward. The MQTT is a concept where your client connect to a broker and publish or subscribe to write/read messages.
Upvotes: 0
Reputation: 2096
You need to find the reason why messages come late. Non-stable network or you are sending too many small messages or you are not using the arduinoWebSockets library correctly?
If all the above does not help, then web browsers are not an option for you, and you will need to create apps for mobiles, which will communicate raw UDP to your server. Browsers cannot do UDP, except WebRTC, but in your case you cannot use WebRTC, because it will simply not run on your low memory esp. WebRTC is a resource hog; not really applicable to DSP.
Upvotes: 3