• Gordon,

    further to the previous thread regarding the RAK8212/BG96, here's a dump of the sequence-

    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     1v99.206 (c) 2018 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >Turning Cell on
    Waiting 30 sec for GPRS connection
    Connecting GPRS
    ["ATE0\r\n"
    ] "ATE0\r\r\nOK\r\n"
    ["AT+CEREG?\r\n"
    ] "\r\n"
    ] "+CEREG: 0,1\r\n\r\nOK\r\n"
    ["AT+CGATT=1\r\n"
    ] "\r\nO"
    ] "K\r\n"
    ["AT+CGREG?\r\n"
    ] "\r\n+"
    ] "CGREG: 0,1\r\n\r\nOK\r\n"
    ["AT+COPS?\r\n"
    ] "\r\n+"
    ] "COPS: 0,0,\"Telstra Mobile Telstra\",9\r\n\r\nOK\r\n"
    ["AT+QICSGP=1,1,\"\",\"\",\"\"\r\n"
    ] "\r\nO"
    ] "K\r\n"
    ["AT+QIACT=1\r\n"
    ] "\r\nO"
    ] "K\r\n"
    Connected!
    >sendCloud()
    {"measurements":[{"source":{"id":"4823986"},"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":"4823986"},"time":"","type":"c8y_SignalStrength"}]}
    ================================
    ["AT+QIOPEN=1,0,\"TCP\",\"11.22.33.44\",8080,0,1\r\n"
    =undefined
    ] "\r\nOK\r\n"
    ] "\r\n"
    ] "+QIOPEN: 0,0\r\n"
    ] "\r\n> "
    ["POST / HTTP/1.1\r\nUser-Agent: Espruino 1v99.206\r\nConnection: close\r\nContent-Type: application/json\r\nContent-Length: 316\r\nAuthorization: Basic ==\r\nHost: \r\n\r\n{\"measurements\":[{\"source\":{\"id\":\"4823986\"},\"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\":\"4823986\"},\"time\":\"\",\"type\":\"c8y_SignalStrength\"}]}"
    ] "\r\nSE"
    ] "ND OK\r\n"
    ] "\r\n+QIURC: \""
    ] "recv\",0,125\r\nHTTP/1.1 200 OK\r\nDate: Tue, 25 Sep 2018 03:56:48 GMT\r\nConnection: cl"
    ] "\r\n\r\n+QIURC: \"close"
    -->Hello world!
    ] "d\",0\r\n"
    ==> Closed.
    >state()
    =undefined
    ] "\r\n+"
    ] "QISTATE: 0,\"TCP\",\"11.22.33.44\",8080,14869,4,1,0,1,\"uart1\"\r\n\r\nO"
    ] "K\r\n"
    >close(0)
    =undefined
    ] "\r\nO"
    ] "K\r\n"
    >state()
    =undefined
    ] "\r"
    ] "\nOK\r\n"
    > 
    

    Note that the ip address and auth have been changed to protect the innocent.
    state() and close() and my functions that issue QISTATE and QICLOSE.

    The function I used to create this:

    function sendCloud() {
      
          if (typeof (http) === 'undefined') {
          http = require("http");
        }
    //  var packet = [ { "compId": compId, "streamId": streamId,"data": data }];
      var packet = {"measurements":[
     {
      "source":{"id":CUMULOCITY_ID},
      "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":CUMULOCITY_ID},
      "time":"",
      "type":"c8y_SignalStrength",
    //   "c8y_SignalStrength":
    //    {
    //     "rssi":{"value":"99","unit":"dBm"},
    //     "BER":{"value":"99","unit":"%"}
    //    }
        }
      ]};
    
      var body=JSON.stringify(packet);
      //var body =JSON.stringify("{'test':'test'}");
      
      //memoryTracking();
      
      options = {
        host: CLOUD_PROVIDER,
          port: '8080',
          path: "/",
          method:'POST',      
          headers: {"Content-Type":"application/json", 
                    "Content-Length": body.length,
                    "Authorization":  AUTH,
                    "Host":""
                   }
      };
      //print(options);
      print(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.");
    //      gprs.at.cmd("AT+QICLOSE=0\r",1E3,print);
        });
      });
      req.end(body);
    }
    
    

    We can see that close is not happening.
    My workaround is adding the QICLOSE into the on "close" method works although it hard codes the socket number.

    Another anomaly is what seems to be a size limitation on the packet which is less than the MTU (around 512 bytes??). The body is truncated and the truncated length is correct to the send request to the module, however the length in the header is the original length, so the server is waiting for more. You can see I've commented out part of the payload I send. When I un-comment it, the send size is 352 bytes even though the packet is larger.

About

Avatar for Kartman @Kartman started