• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Web Serving – sockets, Mosquito, Flask – what’s the best to use?

Q&A Forum › Category: Home Automation › Web Serving – sockets, Mosquito, Flask – what’s the best to use?
0 Vote Up Vote Down
Joe Margevicius asked 1 year ago

Hi.. I’m seeing so many ways to interconnect devices, and need an overview perspective.  In a sense, everything is about controlling something (e.g. LEDs) or receiving data (e.g. temperature sensor data).

 

So, in the “Building WebServers” book, extensive use is made of asyncWebServer/socket (using the server.on(“/xxxx”…) code in the server to handle requests by the client). Then in the “Home Automation” book, extensive use is made of Mosquitto to connect server to client (using onMqttConnect, on MqttMessage, etc code in the server). Then in a tutorial for Raspberry Pi, you introduced Flask+Jinja to handle communications (using @app.route(“/xxxx”…) code in the server). Finally, recently, you published an article with micropython for the RPi Pico (using the more obvious socket.socket() in the server).

This is a daunting collection of ways to connect server and clients. I assume any of these can be used – why would I pick Flask, for example, over Mosquitto or sockets? (I have successfully gone through all the tutorials using ESP32s and Raspberry Pis, and especially use Flash in recent RPi designs, but now I’m scratching my head wondering if I’m using the “best” protocol). Can you comment on these various approaches?

Thanks for any illumination :–)

Question Tags: ESP32, MQTT, Raspberry Pi
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
 
It depends on your preferences and your project requirements and the board you’re using and the libraries available for what you want to do.
 
For example, if you want to use Node-RED to display data, one of the easiest ways to connect several devices is to use MQTT. If you’re using Node-RED, you don’t need to create a web page for the interface, so you won’t need to create a web server, neither HTML or JavaScript files.
 
If you like to customize the way the data is displayed or how your web page looks, you would want something that easily allows you to serve files for web development. For example, I like to use the AsyncWebServer library because you can easily use WebSockets and server-sent events to synchronize everything in real time. And the fact that you can upload web page files (HTML, CSS, and Javascript) using the filesystem is a great advantage because it makes coding much easier. However, it might be a bit overkill for simple projects.
 
There isn’t the “best” protocol, it will really depend on your project and the hardware you have available, and also the way you like to do things (if you’re more of a coding person, or if you like to use “already-made” dashboards.
 
I’m sorry if this is confusing, but this is my opinion about this subject,
 
Regards,
Sara

0 Vote Up Vote Down
Joe Margevicius answered 1 year ago

Hi Sara, Thanks for your answer.  You prompted me to again look at that terrific 600+ page book on Building Web Servers !  …Whew !  … a lot of content, but I’m better informed now with all the protocols in that book, so thanks for the motivation!   I’m happy with using the AsyncWebServer for ESP32 applications, and Flask for Raspberry Pi applications (though I have to dig into Apache since Flask really doesn’t have a production server).  This link (from William Lucid’s questions) helped a little in weighing Firebase, Moquitto and Node-Red.
 
Since this was a very broad question, and the answer is sort of “depends”, I’m good with closing this question out.  – JoeM

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
Yes. That link summarizes in a very broad way the differences between those different methods.
I’ll mark this issue as resolved. If you need further help or have any more questions, you can open a new thread in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.