RED.httpAdmin.get not refreshing JSON

Hi @germancmartinez - when sharing code on the forum please follow the advice in this post: How to share code or flow json. I have edited your post to fix the formatting.

You are creating an interval that runs every 10 seconds to update some data. The problem comes that you add a new route handler to RED.httpAdmin every time. That is not a good idea. You should separate those things out:

  • add one route handler that returns whatever is currently in data
  • create an interval to update data as needed

var data = {};
RED.httpAdmin.get("/equipments/:id", RED.auth.needsPermission('TimeSeries.read'), function(req,res) {
   res.json(data);
});

node.updateEquipmentList = setInterval( async function () {
    var data={};
    if (typeof node.server !== 'undefined' && node.server && typeof node.server.getEquipmentsModel === 'function'){
      data = await node.server.getEquipmentsModel();
      console.log(JSON.stringify(data));
    }
}, 10000);

Finally, make sure you clear the node.updateEquipmentList interval in your node's close handler.

1 Like