2

I am running a python script on a raspberry pi that collects temperature and humidity information, and i have internet server where i have to send that information. I am running node.js on server side, and i made connection between python and node using websockets, but i dont know how to display information in html.

Is it ok to open one socket for communication with python and other for displaying information on html.

1 Answers1

1

To display data on HTML using NodeJS, I think it depends on the embedded JS framework that you're using. Just in case you haven't got knowledge about the embedded JS framework, I would suggest having a look at EJS framework or ExpressJS framework.

I think the repeated flow may be like:

  1. Data is sent to the server with a particular routing method (POST, GET or PUT)
  2. Server captures the request, which contains data in the JSON format.
  3. Server renders the template with the data (This can be done by many embedded JS frameworks but two frameworks above, I think, are simple and popular ones.)

Aside from NodeJS, I think Flask is another simple and quick-to-start alternative to render HTML templates.

Hung Du
  • 124
  • 1
  • 4
  • I have another question, how can i receive data in node. Is it using http module get and post – narutouzumaki 99 Dec 02 '20 at 09:47
  • 1
    If you use Express for routing, you can check out the answer in this post (https://stackoverflow.com/questions/4295782/how-to-process-post-data-in-node-js). Or you can look at the documentation in ExpressJS for routing (https://expressjs.com/en/starter/basic-routing.html). – Hung Du Dec 02 '20 at 10:51