Hosting a Node.js Server on ESP32 or External Hosting for Wi-Fi and Setpoint Form

Vaibhav02
Posts: 5
Joined: Wed Sep 04, 2024 8:09 am

Hosting a Node.js Server on ESP32 or External Hosting for Wi-Fi and Setpoint Form

Postby Vaibhav02 » Fri Sep 06, 2024 6:04 am

I want to implement functionality where I fill a form to provide Wi-Fi credentials and setpoints to an ESP32. The form should send the Wi-Fi credentials and setpoints to the ESP32, and it should then connect to the Wi-Fi network.

I’m using a simple RESTful server sample code and created my own custom form that works properly. My doubt is whether I need to host the code externally or on the ESP32's flash by creating a partition table.

If I run my Node.js server on the ESP32, the frontend can send the response to the backend. However, if I host the website on an external platform, would I also need to host the backend server there as well for it to work properly?

On the ESP32, I’ve noticed that when I upload the folder, it runs index.html (frontend code). What are the best ways to achieve this functionality with ESP32? Should I host both the frontend and backend on the ESP32, or is external hosting a better solution?

MicroController
Posts: 1541
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Hosting a Node.js Server on ESP32 or External Hosting for Wi-Fi and Setpoint Form

Postby MicroController » Fri Sep 06, 2024 7:56 am

Vaibhav02 wrote:
Fri Sep 06, 2024 6:04 am
should send the Wi-Fi credentials and setpoints to the ESP32, and it should then connect to the Wi-Fi network.

If you were to host (part of) the application on a different server, how would that application communicate with an ESP32 which is not yet connected to WiFi?

Vaibhav02
Posts: 5
Joined: Wed Sep 04, 2024 8:09 am

Re: Hosting a Node.js Server on ESP32 or External Hosting for Wi-Fi and Setpoint Form

Postby Vaibhav02 » Fri Sep 06, 2024 8:38 am

I haven't hosted application yet. I am just clearing my doubt. Can I upload backend and frontend on the esp32. If yes then how can the communicate. I didn't clear the concept of this.

ESP_Sprite
Posts: 9568
Joined: Thu Nov 26, 2015 4:08 am

Re: Hosting a Node.js Server on ESP32 or External Hosting for Wi-Fi and Setpoint Form

Postby ESP_Sprite » Fri Sep 06, 2024 10:08 am

Vaibhav02 wrote:
Fri Sep 06, 2024 6:04 am
If I run my Node.js server on the ESP32,
Node.js cannot (meaningfully) run on an ESP32.

MicroController
Posts: 1541
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Hosting a Node.js Server on ESP32 or External Hosting for Wi-Fi and Setpoint Form

Postby MicroController » Fri Sep 06, 2024 1:46 pm

Vaibhav02 wrote:
Fri Sep 06, 2024 8:38 am
Can I upload backend and frontend on the esp32.
Probably not in the way you're thinking of.
An ESP32 will easily run an HTTP server, serving HTML, JavaScript, and other files to a browser; and it will as well receive and process any data sent to it via HTTP, e.g. input into an HTML page/form it also served via HTTP.
It will not run some Node.js (backend) application you may have developed.

The common approach for provisioning ESPs is to, upon first start and/or when it fails to connect to any WiFi network, let the ESP open up a WiFi access point ("SoftAP") and run the HTTP server; a user can then connect to this access point and interact with the ESP via HTTP+HTML, see above. Once the ESP has received all required information, it shuts down its access point and connects to the desired WiFi network in station (STA) mode.

For more options see also https://docs.espressif.com/projects/esp ... oning.html

Who is online

Users browsing this forum: No registered users and 37 guests