HACKER Q&A
📣 willemmerson

Using WebSockets instead of mqtt for IoT


I recently worked on a personal project where I wanted to connect multiple ESP32's to a web app. Previously I've used mqtt to do this and also done this in several work projects, but I decided to try something different and use websockets as ESP-IDF has a websocket client. It worked really well and ended up in a much simpler setup, I didn't need an mqtt broker or a long running process listening to the broker, which meant it was much easier to deploy. Previously I'd had to create a CA and generate self-signed certificates for each device, but with websockets this doesn't seem necessary and is handled transparently by the webserver.

A few other advantages are: - it can have actual end-to-end confirmation, unlike MQTT which is only between client and broker - port 443 won't be blocked - much easier to develop and test locally

So my question is, is anyone else doing this at scale, is there something I haven't thought of?


  👤 tysonfurytoo Accepted Answer ✓
There might be some issues with web sockets over a cellular connection. I'm no expert, but I've read that historically there are issues there. This might not be the case anymore though.

👤 tony-allan
I like the idea of using Websockets for IoT devices if you just need a simple communication mechanism.

I wouldn't do it at scale. Message brokers are battle-hardened for messages at scale, have multiple communication styles, especially pub/sub. They are built for messages at scale.

My interest in Websockets is the same as yours — fewer components (no MQTT server). Works well for a simple message flow and I'm ok with reenventing pub/sub for a small number of devices.


👤 369548684892826
If a client is offline I guess it will never get messages that were sent in that time, I think this might be something that MQTT solves?