You are reading a single comment by @Ken and its replies. Click here to read the full conversation.
  • Has anyone experienced an issue where your HTTP request is never made? The project I'm working on requests some JSON data on a regular basis (60s) from a server. It works the majority of the time but after it runs for a while, it starts to have issues with orphaned requests. I've run this same code against several different servers, hosts, files, etc... both local and remote and still the same issue.

    Below I have a simple test and if you let this code run for a while, it will eventually start to trip up. I have it set to call every 5 seconds for this test but Increasing the time between calls does not help. I've had it 20, 30 & 60 seconds and still the same issue.

    Beyond it's just my network, does anyone have any thoughts? Thank you!

    let timer = null;
    let WIFI = require("Wifi");
    
    function makeRequest(){
      console.log("GET");
      require("http").request({
        "host":"http://www.espruino.com",
        "path":"/",
        "method":"GET",
      }, function(res) {
        res.on('data', function(data) { });
        res.on('close', function(data) { console.log("CLOSED", res.statusCode); });
      }).end();
    }
    
    WIFI.connect(SSID, { password : PWD }, function(err) {
        if (err) {
            console.log("WIFI ERR",err);
            return;
        }
        console.log("Connected to wifi.");
        makeRequest();        
        
        timer=setInterval(()=>{
          makeRequest();
        },5000);
        
    });
    
About

Avatar for Ken @Ken started