• Gordon,
    the close() issue is fixed, but the sending of the remaining data seems to be lingering.

    >sendCloud()
    Length:406 {"measurements":[{"source":{"id":"1234567"},"time":"","type":"CurrentSensor","c8y_CurrentMeasurement":{"Sensor1":{"value":11.1,"unit":"A"},"Sensor2":{"value":22.2,"unit":"A"},"Sensor3":{"value":33.3,"unit":"A"},"Sensor4":{"value":44.4,"unit":"A"}}},{"source":{"id":"1234567"},"time":"","type":"c8y_SignalStrength","c8y_SignalStrength":{"rssi":{"value":"99","unit":"dBm"},"BER":{"value":"99","unit":"%"}}}]}
    ================================
    ["AT+QIOPEN=1,0,\"TCP\",\"11.222.33.123\",80,0,1\r\n"
    =undefined
    ] "\r\nOK\r\n"
    ] "\r\n+QIOPEN: 0,0\r\n"
    ] "\r\n>"
    ] " "
    ["POST /peppap/xxx HTTP/1.1\r\nUser-Agent: Espruino 1v99.225\r\nConnection: close\r\nContent-Type: application/json\r\nContent-Length: 406\r\nAuthorization: Basic NannyPlumRulesYWRp==\r\nHost: \r\n\r\n{\"measurements\":[{\"source\":{\"id\":\"1234567\"},\"time\":\"\",\"type\":\"CurrentSensor\",\"c8y_CurrentMeasurement\":{\"Sensor1\":{\"value\":11.1,\"unit\":\"A\"},\"Sensor2\":{\"value\":22.2,\"unit\":\"A\"},\"Sensor3\":{\"value\":33.3,\"unit\":\"A\"},\"Sensor4\":{\"value\":44.4,\"unit\":\"A\"}}},{\"source\":{\"id\":\"1234567\"},\"time\":\"\",\"type\":\"c8y_SignalStrength\",\"c8y_SignalStrength\":{\"rssi\":{\"value\":\""
    ] "\r\nSEND OK\r\n"
    >state()
    =undefined
    ] "\r\n+QISTATE: 0,\""
    ] "TCP\",\"11.123.33.123\",80,14516,2,1,0,1,\"uart1\"\r\n\r\nOK\r\n"
    >close(0)
    =undefined
    ] "\r\nOK\r\n"
    >state()
    =undefined
    ] "\r\nOK\r\n"
    >sendCloud()
    Length:406 {"measurements":[{"source":{"id":"1234567"},"time":"","type":"CurrentSensor","c8y_CurrentMeasurement":{"Sensor1":{"value":11.1,"unit":"A"},"Sensor2":{"value":22.2,"unit":"A"},"Sensor3":{"value":33.3,"unit":"A"},"Sensor4":{"value":44.4,"unit":"A"}}},{"source":{"id":"1234567"},"time":"","type":"c8y_SignalStrength","c8y_SignalStrength":{"rssi":{"value":"99","unit":"dBm"},"BER":{"value":"99","unit":"%"}}}]}
    ================================
    ["AT+QIOPEN=1,1,\"TCP\",\"11.123.44.123\",80,0,1\r\n"
    =undefined
    ] "\r\nOK\r\n"
    ] "\r\n+QIOPEN: 1,0\r\n"
    ] "\r\nERROR\r\n"
    ["99\",\"unit\":\"dBm\"},\"BER\":{\"value\":\"99\",\"unit\":\"%\"}}}]}"
    >close(0)
    =undefined
    ] "\r\nOK\r\n"
    > 
    

    We can see on the second invocation of sendCloud() that it 'knows' about the left over data, but the send fails.

      options = {
        host: CLOUD_PROVIDER,
          port: '80',
          path: "/peppap/xxx",
          method:'POST',      
          headers: {"Content-Type":"application/json", 
                    "Content-Length": body.length,
                    "Authorization":  CUMULOCITY_AUTH,
                    "Host":""
                   }
      };
      //print(options);
      print(`Length:${body.length} ${body}`);
      console.log("================================");
     
       var req = http.request(options, function(res)  {
        res.on('data', function(data) {
          console.log("-->"+data);
        });
        res.on('close', function(data) {
          console.log("==> Closed.");
        });
      });
      req.end(body);
    
About

Avatar for Kartman @Kartman started