Avatar for aerialist_user6911

aerialist_user6911

Member since Apr 2014 • Last active May 2017
  • 4 conversations
  • 19 comments

Most recent activity

    • 22 comments
    • 1,906 views
  • in JavaScript
    Avatar for aerialist_user6911

    Very interesting to hear about your experience with TI. I hope they have learn lessons and are better now with CC3200/3100. At least they offer free IDE option now.

    ESP8266 is indeed very interesting for its price. Although no hardware encryption, its MCU could be good enough to post tweets. There are quite a few discussion threads with mixed outcomes about SSL. I found these most informative:
    https://github.com/ParsePlatform/parse-e­mbedded-sdks/issues/5
    https://github.com/nodemcu/nodemcu-firmw­are/issues/134

    Have to keep an eye on the progress.

  • in JavaScript
    Avatar for aerialist_user6911

    Well, HTTPS and OAuth seems the de facto standard of web service these days... despite IoT hype. I wonder if a WiFi module with hardware HTTPS and SHA1 capability could come to rescure.

    TI's CC3200 has "Hardware Crypto Engine" and also said to include TLS/SSL stacks along side with ARM M4 processor for applications to run.
    http://www.ti.com/product/cc3200

    Would be interesting if Espruino can run on it!

  • in JavaScript
    Avatar for aerialist_user6911

    Could Espruino handle HTTPS...?

    All twitter REST API resource URL are HTTPS, not HTTP...
    And I've got this error code returned. Yeah, sure. I called require("http").get() function with a URL starting with "https://"...

    Response:  {
      "headers": {
        "content-length": "52",
        "content-type": "application/json;charset=utf-8",
        "date": "Sun, 14 Jun 2015 13:38:10 GMT",
        "server": "tsa_a",
        "set-cookie": "guest_id=v1%3A143428919094643089; Domain=.twitter.com; Path=/; Expires=Tue, 13-Jun-2017 13:38:10 UTC",
        "x-connection-hash": "3e91ae650c8rfb6894d0fc7183fae787",
        "x-response-time": "8"
       },
      "httpVersion": "1.0",
      "statusCode": "403",
      "statusMessage": "Forbidden"
     }
    --->{"errors":[{"message":"SSL is required","code":92}]}
    > 
    

    Oh, these HTTPS and OAuth security things are so tough for micro controllers! We need a good solution to make IoT inexpensive!

  • in JavaScript
    Avatar for aerialist_user6911

    I've got oauth.js and sha1.js running on Esprino Pico alright! (Well, at least included test functions run ok.)

     1v79 Copyright 2015 G.Williams
    >echo(0);
    =undefined
    >process.memory();
    ={ "free": 1323, "usage": 1717, "total": 3040, "history": 1229,
      "stackEndAddress": 536924840, "flash_start": 134217728, "flash_binary_end": 312536, "flash_code_start": 134234112, "flash_length": 393216 }
    >sha1_vm_test()
    =true
    >testEncode();
    =undefined
    >testGetParameters();
    =undefined
    >testGetBaseString();
    =undefined
    >testGetSignature();
    =undefined
    > 
    

    I used minification by Closure Simple Optimisations and have Set Current Time on under Communications setting.

    Now I'need to fight with Twitter API and find out what parameters to throw.
    This seems to be a good reference to follow.
    https://github.com/mogya/tm_twitter_api

  • in JavaScript
    Avatar for aerialist_user6911

    Thanks for your interest, DrAzzy!

    This is right after uploading the code in #9 without minify.

     1v79 Copyright 2015 G.Williams
    >echo(0);
    =undefined
    >process.memory();
    ={ "free": 204, "usage": 2836, "total": 3040, "history": 190,
      "stackEndAddress": 536924840, "flash_start": 134217728, "flash_binary_end": 312536, "flash_code_start": 134234112, "flash_length": 393216 }
    > 
    

    With minification by Esprima.

    >process.memory();
    ={ "free": 1242, "usage": 1798, "total": 3040, "history": 1219,
      "stackEndAddress": 536924840, "flash_start": 134217728, "flash_binary_end": 312536, "flash_code_start": 134234112, "flash_length": 393216 }
    > 
    

    With minification by Closure Simple Optimisation.

    >process.memory();
    ={ "free": 1333, "usage": 1707, "total": 3040, "history": 1218,
      "stackEndAddress": 536924840, "flash_start": 134217728, "flash_binary_end": 312536, "flash_code_start": 134234112, "flash_length": 393216 }
    > 
    

    Pretty good improvement ;-) I continue my endeavour.

  • in JavaScript
    Avatar for aerialist_user6911

    My crude re-mapping of url.parse seems to be doing the job. But...
    Ouch! I've faced with ERROR: Out of Memory...

    Well, as attached, I'm just copying concat codes into Web IDE. I think I'm going to try minify it.

    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v79 Copyright 2015 G.Williams
    >echo(0);
    =undefined
    >testGetParameters();
    ERROR: Out of Memory!
    =undefined
    Uncaught Error: Field or method "length" does not already exist, and can't create it on null
     at line 22 col 29
            if (esp_parse.search.length > 0){
                                 ^
    in function "" callein function "normalizeUrl" called from line 16 col 74
    ...tureMethod.normalizeUrl(URL))
                                   ^
    in function "getBaseString" called from line 2 col 69
    ...ethod.getBaseString(message);
                                   ^
    in function "sign" called from line 7 col 69
    ...ame, accessor).sign(message);
                                   ^
    in function "sign" called from line 21 col 53
            OAuth.SignatureMethod.sign(message, accessor);
                                                         ^
    in function "completeRequest" called from line 33 col 67
    ...sumerKey: 'CK', token: 'T'});
                                   ^
    in function "testGetParameters" called from line 1 col 19
    testGetParameters();
                       ^
    >
    Disconnected
    
  • in JavaScript
    Avatar for aerialist_user6911

    Thanks again, DrAzzy and Gordon. I've got one step closer.

    OAuth URI encoding seem to have some extra ok characters. And it wants to see upper case letters after %. With this modified encodeURIComponent function, Espruino passed testEncode(). Yeah!

    function encodeURIComponent(s) { 
      var ok = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm­nopqrstuvwxyz0123456789-_.~";
      var r = "";
      for (var i=0;i<s.length;i++) { 
        if (ok.indexOf(s[i])>=0) r+=s[i];
        else r+= "%"+(256+s.charCodeAt(i)).toString(16).t­oUpperCase().substr(-2);
      }
      return r;
    }
    

    The next hurdle is regular expression in parseUri function.

        parseUri: function parseUri (str) {
            /* This function was adapted from parseUri 1.2.1
               http://stevenlevithan.com/demo/parseuri/­js/assets/parseuri.js
             */
            var o = {key: ["source","protocol","authority","userIn­fo","user","password","host","port","rel­ative","path","directory","file","query"­,"anchor"],
                     parser: {strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@\/]*­):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?­))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#­]*))?(?:#(.*))?)/ }};
            var m = o.parser.strict.exec(str);
            var uri = {};
            var i = 14;
            while (i--) uri[o.key[i]] = m[i] || "";
            return uri;
        }
    

    Well, Espruino already has url.parse function so I think I could use it with some key re-mapping. I'm going to try...

  • in JavaScript
    Avatar for aerialist_user6911

    Thanks for your encouragement, Gordon!
    I gave it a go and faced that "encodeURIComponent" function is missing.

    Here's what I did:
    Copied sha1.js to Espruino Web IDE and shuffled the order of function definitions a bit, it was sent to Espruino Pico alright. Running sha1_vm_test(); on Pico returned true. Nice ;-)

    Then I added codes from oath.js. It needed minor change (move open curly bracket to the same line as function declaration). With that, it was sent to Pico alright. But running testGetSignature() returned Error: Function "encodeURIComponent" not found!

    I searched around and found that v8 implements it in javascript
    http://v8.googlecode.com/svn/trunk/src/u­ri.js

    Copied it to Web IDE but it refused to send to Pico with message:
    "A corn parse for plugin/compiler.js failed. Check the editor window for syntax errors."

    There are quite a few "!" marks and these lines are labeled "x"

    if (value < 0x10000) {
          %_TwoByteSeqStringSetChar(index++, value, result);
        } else {
          %_TwoByteSeqStringSetChar(index++, (value >> 10) + 0xd7c0, result);
          %_TwoByteSeqStringSetChar(index++, (value & 0x3ff) + 0xdc00, result);
        }
    
    var result = %NewString(array.length, NEW_ONE_BYTE_STRING);
        for (var i = 0; i < array.length; i++) {
          %_OneByteSeqStringSetChar(i, array[i], result);
        }
    

    I'd appreciate any advice to get encodeURIComponent working. I have no idea what these % are doing in javascript...

Actions