Integrating Web Servers | netconn APIs vs. HTTP Server Component

kjames
Posts: 16
Joined: Mon Jul 01, 2019 3:27 pm

Integrating Web Servers | netconn APIs vs. HTTP Server Component

Postby kjames » Sat Mar 07, 2020 7:02 pm

I'm currently using two web servers, one for wifi management and the second for firmware updates, and I need to integrate them one way or another so that I am only using one web server. I have little experience working on this topic, so I could really benefit from suggestions on which way to go.

The wifi manager https://github.com/tonyp7/esp32-wifi-manager: uses netconn functions to serve the HTML page and to support GET/POST requests from a javascript file (code.js in the repo) using Ajax.

The firmware update https://github.com/versamodule/ESP32-OTA-Webserver: uses the ESP IDF HTTP Server component (https://docs.espressif.com/projects/esp ... erver.html) to serve the HTML page which includes javascript. The httpd APIs seem to have better functionality for supporting receiving the file for the firmware update compared to the netconn functions used in the wifi manager.

I think that it would be good to use the HTTP Server component to handle the wifi manager functionality, but I am not sure where to start when it comes to integrating the javascript functionality of the wifi manager web page. I am able to display the page, but due to lack of know-how, I am not sure if those httpd functions can handle Ajax that is used in javascript file that is inlcuded in the wifi manager.

If anyone has an idea of whether or not integrating one way or the other (wifi manager -> firmware upate or vice versa) is a good idea and why, it could at least point me in the right direction.

Thanks

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: Integrating Web Servers | netconn APIs vs. HTTP Server Component

Postby PeterR » Sun Mar 08, 2020 1:29 am

AJAX uses HTTP requests. The AJAX HTTP verbs are initiated by Javascript which runs browser side. No different to any other GET/POST as far as your server is converned. Your server does not know/care that Javascript is involved. There really is no difference between serving HTML, Javascript, Images or AJAX response (headers aside). httpd is fine for AJAX.
Register AJAX handlers for the webpage's GET/POST URI(s). You can grab keys/values from the query string easy enough using httpd. For your response add approrpiate headers and then for your body send the XML/JSON text. You don't need an XML/JSON library, sprintf() would do. If your webpage sends XML well maybe a library is best. That or convert the webpage to use a query string.
Check w3schools, AJAX, XML, JSON are well covered.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: QQ26750452 and 95 guests