• All I do is run the below calls .... one after another it works as expected over 1.5 hour ... even chaining them via callback.

    Then once I start resetting the SIM900 (my own reset) wich completely switches the SIM900 off and back on.

    The first request (getJobs) will fail repeatedly.

    // template for this device
    var device1 = {
        protocol: "v1",
        checksum: "",
        device: "defaultDevice@xyz",
        at: "now",
        data: {}
    };
    
    function post(template, payload, fn, fne) {
      template.data = payload;
      content = JSON.stringify(template);
      var options = {
        host: 'api.carriots.com',
        path: '/status',
        port: '80',
        method:'POST',
        headers: {
          "carriots.apiKey": "aaaaaaaaaaaaaaaaa",
          "Content-Type": "application/json",
          "Content-Length": content.length
        }
      };
      var req = require("http").request(options, function(res)  {
        var d = "";
        res.on('data', function(data) { d+= data; });
        res.on('error', function(data) {
          console.log('error', data);
          if (fne){
            return fne();
          }
        });
        res.on('close', function(data) {
          var obj = JSON.parse(d);
            if (fn){
              return fn(obj);
            }
        });
      }).end(content);
    }
    
    

    the calls are done like:

    function getJobs(fn, fne) {
      var options = {
        host: 'api.carriots.com',
        path: '/streams/?device=Commander@mydevice',
        port: '80',
        method:'GET',
        headers: {
          "carriots.apiKey": "key",
          "Content-Type": "application/json"
        }
      };
      var req = require("http").request(options, function(res)  {
        var d = "";
        res.on('data', function(data) { d+= data; });
        res.on('error', function(data) {
          console.log('error', data);
          if (fne){
            return fne();
          }
        });
        res.on('close', function() {
          var obj = JSON.parse(d);
          if (fn){
            return fn(obj);
          }
          console.log('req closed');
        });
      }).end();
    }
    
    
About

Avatar for sp33c @sp33c started