0

I am using nodeJs and the express, express-handlebars and mqtt packages.

I am recently trying to update a table which shows the content of the current temperature outside and inside. This table is only a part of the website making it worth striving to just update this particular talbe each second. Therefore, using does not seem like the right answer for me and also harms the ability to set settings and click on a link.

I have already tried using the Query .load function which indeed works but does not work properly together with express-handelbars. Instead of the content transmitted to my server via MQTT, {{temperatureInside}} and {{temperatureOutside}} is shown on the website.

Any ideas how to solve this problem?

JayJay
  • 43
  • 2
  • 13
  • when you say you are trying to "update" it, do you mean that you want it to be automatically updated (as in the server notifies the front end of changes), or do you want to add a record to it (now it has a new value, so it is "updated") – Corbfon Jan 16 '17 at 17:45
  • I want it to be updated automatically – JayJay Jan 16 '17 at 17:49

1 Answers1

2

In the case that you want the table to be updated automatically, that means you need the server to tell the front end that there is new data. This is not possible with standard HTTP requests, which is why some clever person built Websockets (WSS protocol). Using Node, a the library I use for this is socket.io

socket.io has code that needs to be both imported on the front end (tells your client how to talk through WSS) and required on the Node side (npm install socket.io --save)

From there, you can set up custom events that both your server and client understand. I'll leave you to go through the docs, but socket.io would certainly do the trick for you. I've used it in many similar circumstances.

Corbfon
  • 3,514
  • 1
  • 13
  • 24
  • See [this answer](http://stackoverflow.com/questions/26791107/websockets-wss-on-http-vs-wss-on-https) – Corbfon Jan 17 '17 at 20:36