Avatar for andiy

andiy

Member since Oct 2015 • Last active Oct 2016
  • 2 conversations
  • 6 comments

Most recent activity

    • 3 comments
    • 1,838 views
  • in JavaScript
    Avatar for andiy

    use global.setInterval

    does not help - now the global var itself gets accused by the linter ;)

    However, Espruino doesn't pay any attention to use strict

    imho that's ok - to get some hints in the editor is already great!

  • in JavaScript
    Avatar for andiy

    code using the 'use strict' directive is identified by the editor, but
    brings up error message for built-in library functions (see attached image)

    function test_strict(){
      "use strict";
      
      var N=false;   // oops - typo...
      setInterval( function(){
        LED2.write( n);
        n = !n;
      },1000);
    }
    

    is there any libraray available to satisfy the editor's strict validator?

    ps: the esprima minifyer ignores the strict directive, and reports even bad code to be fine

  • in Interfacing
    Avatar for andiy

    it's literally data.length+"\r\n"+data+"\r\n"?

    be aware of base 16 encoding of data.length - e.g. data.length.toString(16)

    ps: respect - i am absolutely surprised about your speedy response - i'll check out your update 'till tomorrow morning (CET ;)

  • in Interfacing
    Avatar for andiy

    epsruino board 1v4, fw 1v80, cc3000, http client

    i expted the code below to send 3 chunks (snippet#1):

    function post_test1(){       
    var o = {
    host: BACKEND_IP,
    port: BACKEND_PORT,
    path: BACKEND_ROOT, 
    method:'POST',
    headers: {
      "Content-Type" : "application/json",
      "Transfer-Encoding": 'chunked'
    }
    };
    var req= http.request( o, function(res)  {    
    res.on('close', function() { 
      console.log( 'post closed',res.statusCode);  
    });       
    res.on('end', function() { 
      console.log( 'post end',res.statusCode);  
    });       
    });
    
    setTimeout( function(){
      var c = 'abcd';
      console.log('sending',c);
      req.write( c);         
    }, 1000);
    
    setTimeout( function(){
      var c = 'zyxw';  
      console.log('sending',c);
      req.write( c);         
    }, 3000);
    
    setTimeout( function(){
      c='the end';
      console.log('sending',c);
      req.end( c);         
    }, 5000);
    }
    

    but there is nothing (not even a header) received by the server. i detected two major issues.

    A) the req object does mostly not work in the setTimeout callback - reqseems to be valid until next idle state only (or a few milliseconds longer 'cause the bad code below worked in very seldom trials)

    // this is fine - snippet#2a
      req.write( 'abcd');         
      req.end( 'the end');         
    
    // this is - mostly - bad - snippet#2b
    req.write( 'abcd');         
    setTimeout( function(){
      req.end( 'the end');         
    }, 1000);
    

    B) req.write(...) does not produce a chunked payload / does not encode chunks;

    // this should send two chunks: - snippet#3a
      req.write( 'abcd');         
      req.end( 'the end');         
    

    at least it sends the data, but does no chunk encoding

    // the chunk encoding has to be added manually:- snippet#3b
      req.write( '4\r\nabcd\r\n');         
      req.end( '7\r\nthe end\r\n0\r\n\r\n');
    

    the code snippet#1 runs from node.js 0.12.4 as expected. seems that the espruino http client does some things different from node.js' http client (which applies chunked encoding by default - as long as you to not set the content-length header).

    is any workaround / solution possible?

    thx!

Actions