2

I'm intending to create some (like 5-10) boxes with sensors and/or relays inside using ESP32's.

For connection to a laptop and mobile phone I found a tutorial at ESP32 WebSocket Server: Control Outputs (Arduino IDE) which uses an async webserver with sockets.

However, I wonder if I would use multiple boxes, how to solve this. I thought of one of the following 'solutions"

I want to have the boxes work together (e.g. to make a web page that I can set that e.g. when sensor X has value Y than on another box relay 1 should be on).

  • Making each a webserver. But having 5-10 webservers seem hard to handle as I don't want to visit 10 web pages for each server on my laptop/mobile phone.
  • Make one of them the webserver. But this seems strange as they are all more or less equal (they will have different sensors but that's not relevant for the webserver functionality).
  • Create a separate webserver (on an ESP32), that does nothing except handling all data.

I guess the second or third solution is best. Than my next question would be what is the best way to have the boxes communicate to each other. Can I for example have a websocket for the HTML page(s) on the laptop/mobile phone to the server and next to that use HTTP messages to communicate with all other boxes?

I hope this questions is not too generic, I'm just a newbie to webservers/sockets.

Note, I prefer to use my router as this is in the middle of the house and all my boxes will be within vicinity of it (more or less close).

1

2 Answers 2

4

I'd suggest using MQTT to configure the ESP32's as clients to publish/subscribe. You can use a Raspberry Pi (A 0W will work, but a 3 or 4 is better) as the broker, and look at your data (or control your relays) through a Node Red web interface. Check some of the other randomnerd tutorials for details...

5
  • Thanks, I was hoping to use a non MQTT way (also as it would be fun to make a solution myself but maybe that's overkill). Dec 22, 2021 at 8:51
  • I have some RaspBerry 2's, so hope that will work. Dec 22, 2021 at 11:44
  • 1
    @MichelKeijzers you could pull data from all of the boxes using node-red on a computer ... mqtt is not necessary
    – jsotola
    Dec 22, 2021 at 18:54
  • @jsotola Yes I read a bit about it ... however, the downside is that my computer needs to be on all the time, not sure if I want that. Another possibility seems an online broker. However, I have a few Raspberry 2's I found (not sure if they work, and no experience with Raspberry's yet). Dec 22, 2021 at 21:22
  • 1
    here is an online broker with visual feedback ... a downloadable version is available ... shiftr.io/try ... useful for developing a system
    – jsotola
    Dec 22, 2021 at 21:39
2

In a distributed system like this, the key questions are where the 'intelligence' for the system will reside, how it will communicate with the peripherals, and what interface you need to configure & monitor the system.

Personally I think the Async Webserver plus Websocket technique is an overly complex solution to this problem; you could just run an ordinary non-async Web server on each ESP32, which takes in requests for data, and also accepts settings, for example if you request the Web page "status.csv" you get a comma-delimited list of values of your sensors, and "control.htm?output1=1&output2=0" would set the two outputs accordingly.

When it comes to communication between the sensor boxes, it is generally not a good idea to distribute the intelligence amongst them, as programming and debugging 5 or more inter-communicating systems can be really hard work; it is much easier to have a single coordinator that controls everything. This would preferably be a disk-based system, so you can log all the data for diagnostic purposes.

You will presumably need a way of displaying & changing the system status and nowadays that is generally a Web page, which could be served up by the management system. When running on a browser, it would use javascript AJAX calls to fetch the data from the peripherals, and generate a pretty display; I've used this technique in an ESP32 oscilloscope project

The key advantage of having a Web-based system is that you can point your Web browser at any of the ESP32 units, and get it its raw data - this is very useful if something has gone wrong, and you want to check if it is due to a fault with one of the remote units, or a bug in the management software.

1
  • Thanks for this info, which seems also a good way to go. However, I decided to take the MQTT approach which is more suitable for my 'home automation' project. Feb 7 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.