looking for some solutions? You are welcome.

SOLVED: Rendering variable to ejs template? (MQTT client)

Thiago Farias:

My ejs side (webpage) is updating the wrong variables every time I refresh the page,but each variable has a different name. I cannot figure out what is wrong.

My index.js is receiving messages from an esp8266 using MQTT, and then I render that to the ejs.


var content = { doorMsg: "Door Closed" ,
                windowMsg: "Window Closed",
                tempMsg : "",
                moistureMsg : "" ,
                motionMsg: "Motion" };

// ...here esp8266 updates one o thoses doorMsg,windowMsg, tempMsg, moistureMsg, motionMsg ...

/* GET home page. */
router.get('/', function(req, res) {
    res.render('index', {  content : content } );


<h4> <%= content.moistureMsg %> </h4>
<h4> <%= content.motionMsg %> </h4>
<h4> <%= content.windowMsg %> </h4>
<h4> <%= content.doorMsg %> </h4>

content.moistureMsg sometimes showing what is suppose to be to content.windowMsg , or content.doorMsg is showing the value that is suppose to be to content.motionMsg. A complete mess...

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots

No comments: