idf 4.4 restful_server example

bmartin0
Posts: 33
Joined: Tue Aug 03, 2021 10:38 pm

idf 4.4 restful_server example

Postby bmartin0 » Fri May 20, 2022 12:48 pm

Hello,
I'm trying to run the restful_server example in idf4.4. I can build the program but get the following in the output window:
Make Error at main/CMakeLists.txt:10 (message):
C:/Workspace/Eclipse/restful_server/main/../front/web-demo/dist doesn't
exit. Please run 'npm run build' in
C:/Workspace/Eclipse/restful_server/main/../front/web-demo

Via the command terminal "ESP-IDF 4.4 CMD" I switch to the web-demo dir and run "npm run build". I'm getting the following output:

'npm' is not recognized as an internal or external command,
operable program or batch file.

Can someone explain how to install npm?

Thanks

glrtheil
Posts: 61
Joined: Tue Dec 07, 2021 2:48 pm

Re: idf 4.4 restful_server example

Postby glrtheil » Fri May 20, 2022 5:15 pm

npm isn't used to compile esp-idf stuff. You need to run "idf.py build" from your project directory. Unless I'm confused about the project you're building. If you do need npm, you need to install node: https://nodejs.org/en/

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: idf 4.4 restful_server example

Postby mbratch » Fri May 20, 2022 7:58 pm

The rest server example needs a client to exercise it to be a complete example. Espressif has chosen to use a nodejs client as an example. That's the stuff under the "front" subfolder. To build that, you need to install nodejs. `npm` is part of nodejs. It's not part of the ESP32 toolchain, it's a separate thing.

bmartin0
Posts: 33
Joined: Tue Aug 03, 2021 10:38 pm

Re: idf 4.4 restful_server example

Postby bmartin0 » Sun May 22, 2022 7:32 pm

Ok, thanks for the help. I'll install nodejs and see if I can get it to work.
thanks

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: idf 4.4 restful_server example

Postby mbratch » Sun May 22, 2022 8:29 pm

@bmartin0 you could also install a program like Insomnia or Postman. Either of these would allow you to send a PUT or POST request with the parameters you want to the ESP32 server and see the results. If you want to get into writing a REST interface, I highly recommend getting one of these as a useful tool. Nodejs is just the tool the example uses to send the REST commands, but you could use either of these as well.

bmartin0
Posts: 33
Joined: Tue Aug 03, 2021 10:38 pm

Re: idf 4.4 restful_server example

Postby bmartin0 » Sun May 22, 2022 10:52 pm

I downloaded nodejs and got it working. I used a browser and set it to the IP on the serial term. It seems to be working fine now. Just need to figure out how it works. Kinda new to this webserver stuff. I get IP 10.0.0.115 and can go to that via chrome and the web page shows up no problem. Just have to study it now as I'm not sure how to take this code and use esp32 values such as real time data I've gathered and post them to this webpage, i.e. use real ad data an update the plot that this code is showing. I think I need an asynchronous webserver but not sure how to get the data pushed to it in a repetitive fashion such as once per second.
This is a big step forward and I really appreciate all the comments and help from all involved.
Thank you very much!

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: idf 4.4 restful_server example

Postby mbratch » Sat May 28, 2022 3:56 pm

bmartin0 wrote:
Sun May 22, 2022 10:52 pm
I think I need an asynchronous webserver but not sure how to get the data pushed to it in a repetitive fashion such as once per second.
If you mean that you want the web page to update automatically based upon data pushed from the ESP32, then you probably want to use websockets. ESP-IDF supports websocket server. The alternative would be to use a timer in the client side javascript to pull the data at regular intervals. The advantage of the websocket is that it can push the data only if and when it changes.

Who is online

Users browsing this forum: No registered users and 86 guests