You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • After some wifi connectivity skirmishes with the CC3000 module - see - I'n now ready to read data... this is the code I'm using:

    var SSID = "MySSID";
    var WPA2Key = "MyWPA2Key";
    
    var log = function(s,e) { 
      var p = "" + (Math.round((getTime() - t0) * 1000) / 1000) + "000";
      var d = p.indexOf("."); console.log(((e) ? "E: " : "-: ") + ((p < 0) ? 
        p.substr(p.length - 3) + ".000" : p.substr(0,d + 4)) + ": "+ s);
    };
    
    var t0 = getTime();
    log("Connecting to CC3000...");
    var wlan = require("CC3000").connect();
    if (wlan) {
      log("Connecting to wifi access point...");
      wlan.connect( SSID, WPA2Key, function (s) {
        log("Connected with " + s);
        if (s == "dhcp") {
          require("http").get("http://54.148.129.10/ldbwsService.php", function(res) {
            var str = "";
            res.on('data', function(data) {
              log(">" + data);
              str += data;
            });
            res.on('close', function() {
              log("str: " + str);
              var obj = JSON.parse(str);
              log("obj: "); console.log(obj);
              var mem = process.memory();
              log("Memory free: " + mem.free + "  -  usage: " + mem.usage);
              wlan.disconnect();
              log('CC3000 disconnected.');
            });
          });
        }
      });
    } else {
      log("Did not get wlan object / not connected to CC3000.",1);
    }
    

    And this is the expected response - so far in the console... is:

    1. response fragments (>)
    2. response string - a JSON string, all of it (str: ....)
    3. JSON parsed object (obj: ...)

    The time is in [s].[ms] to give a feeling about the speed behavior:

    • about 20[s] for to connect
    • about 1.5[s] for sending the request, get the response, and parse it into an object.

            |_| http://espruino.com
      1v71 Copyright 2014 G.Williams
      >echo(0);
      -: 0.001: Connecting to CC3000...
      -: 2.629: Connecting to wifi access point...
      =undefined
      -: 9.079: Connected with connect
      -: 19.227: Connected with dhcp
      -: 19.229: Sending request
      -: 20.418: >{"generatedA
      -: 20.423: >t":"2015-01-12T07:36:00.9734935+00:00","locationName":"Reading",
      -: 20.429: >"crs":"RDG","platformAvailable":true,"nrccMessages":"","trainSer
      -: 20.435: >vices":[{"origin":{"locationName":"Reading","crs":"RDG"},"destin
      -: 20.441: >ation":{"locationName":"London Paddington","crs":"PAD"},"std":"0
      -: 20.447: >7:34","etd":"07:36","platform":"14","serviceID":"9yEl2b7IcoQGhuh
      -: 20.452: >J7UqicA==","subsequentCallingPoints":[{"locationName":"Twyford",
      -: 20.458: >"st":"07:41","et":"On time"},{"locationName":"Maidenhead","st":"
      -: 20.464: >07:49","et":"On time"},{"locationName":"Taplow","st":"07:53","et
      -: 20.470: >":"On time"},{"locationName":"Burnham","st":"07:56","et":"On tim
      -: 20.476: >e"},{"locationName":"Slough","st":"08:01","et":"On time"},{"loca
      -: 20.482: >tionName":"Langley","st":"08:06","et":"On time"},{"locationName"
      -: 20.487: >:"West Drayton","st":"08:11","et":"On time"},{"locationName":"Ha
      -: 20.493: >yes & Harlington","st":"08:16","et":"On time"},{"locationName":"
      -: 20.499: >Southall","st":"08:20","et":"On time"},{"locationName":"Ealing B
      -: 20.505: >roadway","st":"08:25","et":"On time"},{"locationName":"London Pa
      -: 20.511: >ddington","st":"08:38","et":"On time"}],"operator":"First Great
      -: 20.517: >Western","operatorCode":"GW"},{"origin":{"locationName":"Worcest
      -: 20.523: >er Shrub Hill","crs":"WOS"},"destination":{"locationName":"Londo
      -: 20.529: >n Paddington","crs":"PAD"},"std":"07:35","etd":"On time","platfo
      -: 20.535: >rm":"11","serviceID":"vUUvejQm7x3F4dRM+SqC1g==","subsequentCalli
      -: 20.540: >ngPoints":"","operator":"First Great Western","operatorCode":"GW
      -: 20.546: >"},{"origin":{"locationName":"Reading","crs":"RDG"},"destination
      -: 20.552: >":{"locationName":"Basingstoke","crs":"BSK"},"std":"07:37","etd"
      -: 20.558: >:"On time","platform":"2","serviceID":"I25K292y51sCtA1NaP7\/Gg==
      -: 20.564: >","subsequentCallingPoints":"","operator":"First Great Western",
      -: 20.570: >"operatorCode":"GW"},{"origin":{"locationName":"Frome","crs":"FR
      -: 20.576: >O"},"destination":{"locationName":"London Paddington","crs":"PAD
      -: 20.582: >"},"std":"07:39","etd":"On time","platform":"8","serviceID":"qcq
      -: 20.588: >riRjZax87JaIWts3i6g==","subsequentCallingPoints":"","operator":"
      -: 20.594: >First Great Western","operatorCode":"GW"}]}
      -: 20.641: str: {"generatedAt":"2015-01-12T07:36:00.9734935+00:00","locationName":"Reading","crs":"RDG","platformAvailable":true,"nrccMessages":"","trainServices":[{"origin":{"locationName":"Reading","crs":"RDG"},"destination":{"locationName":"London Paddington","crs":"PAD"},"std":"07:34","etd":"07:36","platform":"14","serviceID":"9yEl2b7IcoQGhuhJ7UqicA==","subsequentCallingPoints":[{"locationName":"Twyford","st":"07:41","et":"On time"},{"locationName":"Maidenhead","st":"07:49","et":"On time"},{"locationName":"Taplow","st":"07:53","et":"On time"},{"locationName":"Burnham","st":"07:56","et":"On time"},{"locationName":"Slough","st":"08:01","et":"On time"},{"locationName":"Langley","st":"08:06","et":"On time"},{"locationName":"West Drayton","st":"08:11","et":"On time"},{"locationName":"Hayes & Harlington","st":"08:16","et":"On time"},{"locationName":"Southall","st":"08:20","et":"On time"},{"locationName":"Ealing Broadway","st":"08:25","et":"On time"},{"locationName":"London Paddington","st":"08:38","et":"On time"}],"operator":"First Great Western","operatorCode":"GW"},{"origin":{"locationName":"Worcester Shrub Hill","crs":"WOS"},"destination":{"locationName":"London Paddington","crs":"PAD"},"std":"07:35","etd":"On time","platform":"11","serviceID":"vUUvejQm7x3F4dRM+SqC1g==","subsequentCallingPoints":"","operator":"First Great Western","operatorCode":"GW"},{"origin":{"locationName":"Reading","crs":"RDG"},"destination":{"locationName":"Basingstoke","crs":"BSK"},"std":"07:37","etd":"On time","platform":"2","serviceID":"I25K292y51sCtA1NaP7\/Gg==","subsequentCallingPoints":"","operator":"First Great Western","operatorCode":"GW"},{"origin":{"locationName":"Frome","crs":"FRO"},"destination":{"locationName":"London Paddington","crs":"PAD"},"std":"07:39","etd":"On time","platform":"8","serviceID":"qcqriRjZax87JaIWts3i6g==","subsequentCallingPoints":"","operator":"First Great Western","operatorCode":"GW"}]}
      -: 20.667: obj:
      {
      "generatedAt": "2015-01-12T07:36:00.9734935+00:00",
      "locationName": "Reading",
      "crs": "RDG",
      "platformAvailable": true,
      "nrccMessages": "",
      "trainServices": [
      {
        "origin": {
      "locationName": "Reading",
      "crs": "RDG"
         },
        "destination": {
      "locationName": "London Paddington",
      "crs": "PAD"
         },
        "std": "07:34",
        "etd": "07:36",
        "platform": "14",
        "serviceID": "9yEl2b7IcoQGhuhJ7UqicA==",
        "subsequentCallingPoints": [
      {
      "locationName": "Twyford",
      "st": "07:41",
      "et": "On time"
      },
      {
      "locationName": "Maidenhead",
      "st": "07:49",
      "et": "On time"
      },
      {
      "locationName": "Taplow",
      "st": "07:53",
      "et": "On time"
      },
      {
      "locationName": "Burnham",
      "st": "07:56",
      "et": "On time"
      },
      {
      "locationName": "Slough",
      "st": "08:01",
      "et": "On time"
      },
      {
      "locationName": "Langley",
      "st": "08:06",
      "et": "On time"
      },
      {
      "locationName": "West Drayton",
      "st": "08:11",
      "et": "On time"
      },
      {
      "locationName": "Hayes & Harlington",
      "st": "08:16",
      "et": "On time"
      },
      {
      "locationName": "Southall",
      "st": "08:20",
      "et": "On time"
      },
      {
      "locationName": "Ealing Broadway",
      "st": "08:25",
      "et": "On time"
      },
      {
      "locationNa e": "London Paddington",
      "st": "08:38",
      "et": "On time"
      }
         ],
        "operator": "First Great Western",
        "operatorCode": "GW"
       },
      {
        "origin": {
      "locationName": "Worcester Shrub Hill",
      "crs": "WOS"
         },
        "destination": {
      "locationName": "London Paddington",
      "crs": "PAD"
         },
        "std": "07:35",
        "etd": "On time",
        "platform": "11",
        "serviceID": "vUUvejQm7x3F4dRM+SqC1g==",
        "subsequentCallingPoints": "",
        "operator": "First Great Western",
        "operatorCode": "GW"
       },
      {
        "origin": {
      "locationName": "Reading",
      "crs": "RDG"
         },
        "destination": {
      "locationName": "Basingstoke",
      "crs": "BSK"
         },
        "std": "07:37",
        "etd": "On time",
        "platform": "2",
        "serviceID": "I25K292y51sCtA1NaP7/Gg==",
        "subsequentCallingPoints": "",
        "operator": "First Great Western",
        "operatorCode": "GW"
       },
      {
        "origin": {
      "locationName": "Frome",
      "crs": "FRO"
         },
        "destination": {
      "locationName": "London Paddington",
      "crs": "PAD"
         },
        "std": "07:39",
        "etd": "On time",
        "platform": "8",
        "serviceID": "qcqriRjZax87JaIWts3i6g==",
        "subsequentCallingPoints": "",
        "operator": "First Great Western",
        "operatorCode": "GW"
       }
      ]
      }
      -: 20.724: Memory free: 1469  -  usage: 781
      -: 20.727: CC3000 disconnected.
      > 
      

    The very very first request brought the response string in on shot. I then added the JASON.parse to the simple sample code as described in Clienbt paragraph on CC3000 Module page. In great anticipation... nope: all following requests brought only a very tiny fragment containing: {requestedA. That was all. Some more reading - notably from the overall Internet (HTTP) page - lead back to working code again. Even though it is only a single shot at data, I'm satisfied for now. More later.

About

Avatar for allObjects @allObjects started