Avatar for KevinJ

KevinJ

Member since Sep 2017 • Last active Sep 2017
  • 2 conversations
  • 6 comments

Senior Front End Developer at Redfin
Complete noob when it comes to hardware.
Seattle, WA

Most recent activity

  • in Projects
    Avatar for KevinJ

    There are a couple other posts that have talked about NPM and Webpack, some that mention Babel, but I thought I would start a new post. I'm relative noob to espruino stuff, but an experienced web developer, so I thought I would share my thoughts about the toolchain.

    A little about Babel for those who don't know it:

    • Its primary usage is a polyfill for ES standards that don't exist in whatever environment you're running your code on. For instance, some browsers don't understand Object.assign(..., but Babel can make that syntax available to many environments (mostly browsers of various vintages)
    • Has a rich ecosystem of presets and plugins that do various transforms on javascript code before it gets run or sent to production.
    • Very well supported, an absolutely insensible tool for almost every modern web company, including Facebook, AirBnB, Reddit, and where I work, Redfin.
    • Babel has a CLI that is fast and runs on node and in the browser, this opens many possibilities for the Espruino ecosystem.

    Overall thoughts:

    • Im a big baby and want to be able to work in the tools I'm familiar with. I'm sure I'll offend someone by saying this, but the Espruino IDE is a bit lacking, compared to what tools are available to web developers such as Atom or Sublime.
    • When I started on Espruino, I had expected that I would just be able to create a new file on my local disk, use my editor of choice to write code, and have a bulletproof CLI to send it to the device and get logging back. For instance React Native (a project that runs Javascript on iOS and Android) has very simple tools to build and watch local files and move them to the device. I want this for espruino.
    • A babel-preset-espruino would be extremely useful and amazing. Moving from my day job where I write JS thats run through babel, then coming home and playing with espruino, I feel like I walked into a time machine that took me back a few years. No module syntax, no async/await, persistent fear of using a language feature that is going to blow up on my target environment. Its not optimal.

    Actual question:

    After reading through the docs I'm actually a bit suprised that I didn't find a simple single command to just deploy and run a static JS file on a board plugged in via usb and get a non interactive log back.
    Hello world:
    $ npm install espruino -g
    $ touch index.js
    edit file, write a simple blink app
    plug in board via usb
    $ espruino run index.js (with options to specify a port if you need to to that)
    then the terminal shows the std out from the app as it runs

    I also expected a good watch mode for local files, which would look like such
    $ espruino watch index.js
    cli starts the app, and runs it
    then you make changes, hit save in your editor and the terminal window shows:
    changes found, restarting
    then the terminal shows the std out from the app as it runs

    Did I miss some docs somewhere or is a CLI like this not available?

  • in Pico / Wifi / Original Espruino
    Avatar for KevinJ

    Thanks for the thoughtful replies, totally cleared things up. I was just thrown off a bit by the docs. I only had a brief introduction to arduino itself, so I had totally blanked out on the lifecycle event handling on board power on and jumped right into the code.

    That said, I think the espruino docs themselves are a bit light on the reminders to put more than the most bare bones examples into a proper init method and make sure things are loaded. Was there a tech article that I missed that gives some advice there that I missed? If not I'd be game to try and write one out myself, are open source contributions to the docs encouraged?

  • in Pico / Wifi / Original Espruino
    Avatar for KevinJ

    edit: remove dupe post

  • in Pico / Wifi / Original Espruino
    Avatar for KevinJ

    Here is the console output for debug:

    Initialising CodeLink
    Initialising Project
    Initialising Testing
    Initialising Notification_Sound
    Initialising Tern
    Initialising Debugger
    Initialising Tour
    Initialising SettingsProfile
    Initialising HelpLinks
    Initialising Offline
    Loaded code from storage.
    GET chrome.storage.local.OFFLINE_DATA = 0 bytes
    >>> Connecting...
    ForceThrottle option is set - set Slow Write = true
    [object Object]
    Connected [object Object]
    Found a prompt... great!
    >>> Sending...
    ---> "\u0010console.log(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n"
    >>> Sent
    WARNING: No result found - just got "<- Serial1\r\n>< << {\"VERSION\":\"1v91\",\"BUILD_DATE\":\"Jan 12 2017\",\"BUILD_TIME\":\"10:55:52\",\"GIT_COMMIT\":\"a6300790b771b7afffdb2bb2d8c5d0607f7977ef\",\"BOARD\":\"ESPRUINOWIFI\",\"CHIP\":\"STM32F411CEU6\",\"CHIP_FAMILY\":\"STM32F4\",\"FLASH\":524288,\"RAM\":131072,\"SERIAL\":\"43001d00-0b513532-39333638\",\"CONSOLE\":\"USB\",\"EXPORTS\":{\"jsvLock\":336089,\"jsvLockAgainSafe\":336075,\"jsvUnLock\":336049,\"jsvSkipName\":184381,\"jsvMathsOp\":141949,\"jsvMathsOpSkipNames\":141995,\"jsvNewFromFloat\":336405,\"jsvNewFromInteger\":336441,\"jsvNewFromString\":339205,\"jsvNewFromBool\":336425,\"jsvGetFloat\":184749,\"jsvGetInteger\":180485,\"jsvGetBool\":185337,\"jspeiFindInScopes\":145525,\"jspReplaceWith\":154073,\"jspeFunctionCall\":150877,\"jspGetNamedVariable\":145585,\"jspGetNamedField\":146857,\"jspGetVarNamedField\":146449,\"jsv"
    Device found (connectionId=1)
    [success] Connected to port /dev/tty.usbmodem1421
    >>> Connected to port /dev/tty.usbmodem1421
    Disconnect callback...
    WARNING: [notify_warn] Disconnected
    >>> Disconnected
    >>> Connecting...
    ForceThrottle option is set - set Slow Write = true
    [object Object]
    Connected [object Object]
    Found a prompt... great!
    >>> Sending...
    ---> "\u0010console.log(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n"
    >>> Sent
    WARNING: No result found - just got "NewWithFlags\":336245}} >> >\r\n>< << {\"VERSION\":\"1v91\",\"BUILD_DATE\":\"Jan 12 2017\",\"BUILD_TIME\":\"10:55:52\",\"GIT_COMMIT\":\"a6300790b771b7afffdb2bb2d8c5d0607f7977ef\",\"BOARD\":\"ESPRUINOWIFI\",\"CHIP\":\"STM32F411CEU6\",\"CHIP_FAMILY\":\"STM32F4\",\"FLASH\":524288,\"RAM\":131072,\"SERIAL\":\"43001d00-0b513532-39333638\",\"CONSOLE\":\"USB\",\"EXPORTS\":{\"jsvLock\":336089,\"jsvLockAgainSafe\":336075,\"jsvUnLock\":336049,\"jsvSkipName\":184381,\"jsvMathsOp\":141949,\"jsvMathsOpSkipNames\":141995,\"jsvNewFromFloat\":336405,\"jsvNewFromInteger\":336441,\"jsvNewFromString\":339205,\"jsvNewFromBool\":336425,\"jsvGetFloat\":184749,\"jsvGetInteger\":180485,\"jsvGetBool\":185337,\"jspeiFindInScopes\":145525,\"jspReplaceWith\":154073,\"jspeFunctionCall\":150877,\"jspGetNamedVariable\":145585,\"jspGetNamedField\":146857,\"jspGetVarNamedField\":146449,\"jsv"
    Device found (connectionId=2)
    [success] Connected to port /dev/tty.usbmodem1421
    >>> Connected to port /dev/tty.usbmodem1421
    loadModule(DS18B20)
    loadModule(EspruinoWiFi)
    loadModule(http)
     - DS18B20 requires []
     - EspruinoWiFi requires ["AT","NetworkJS"]
       Queueing AT
       Queueing NetworkJS
    ERROR: Not Found
    loadModule(AT)
    loadModule(NetworkJS)
    ERROR: Not Found
    WARNING: [notify_warn] Module http not found
     - AT requires []
    ERROR: Not Found
    ERROR: Not Found
    WARNING: [notify_warn] Module NetworkJS not found
    Received a prompt after sending newline... good!
    >>> Sending...
    ---> "\u0010reset();\n\u0010setTime(1505076492.952);\n\u0010Modules.removeAllCached();\n\u0010Modules.addCached(\"AT\",\"exports.connect=function(l){var m=!1,a=\\\"\\\",d,b={},e={},g=[];l.on(\\\"data\\\",function(f){a+=f;m&&console.log(\\\"] \\\"+JSON.stringify(a)+\\\" <--- \\\"+JSON.stringify(f));\\\"\\\\n\\\"==a[0]&&(a=a.substr(1));if(b){b[\\\">\\\"]&&\\\">\\\"==a[0]&&(a=b[\\\">\\\"](a));for(var c in b)a.substr(0,c.length)==c&&(a=b[c](a))}for(f=a.indexOf(\\\"\\\\r\\\");0<=f;){var k=a.substr(0,f);if(0<k.length){var n=!1;for(c in e)k.substr(0,c.length)==c&&(e[c](k),n=!0);n||d&&d(k)}a=a.substr(f+1);\\\"\\\\n\\\"==a[0]&&(a=a.substr(1));if(a.length&&b)for(c in b[\\\">\\\"]&&\\\">\\\"==\\na[0]&&(a=b[\\\">\\\"](a)),b)a.substr(0,c.length)==c&&(a=b[c](a));f=a.indexOf(\\\"\\\\r\\\")}});var h={debug:function(){m=!0;return{line:a,lineCallback:d,handlers:b,lineHandlers:e,waiting:g}},cmd:function(a,c,b){if(d)g.push([a,c,b]);else if(m&&console.log(\\\"[\\\"+JSON.stringify(a)),l.write(a),c){var e=setTimeout(function(){d=void 0;b&&b()},c),p=function(a){d=void 0;var f;b&&(f=b(a))?(d=p,b=f):clearTimeout(e);void 0===d&&0<g.length&&(a=g.shift(),h.cmd(a[0],a[1],a[2]))};d=p}},write:function(a){l.write(a)},cmdReg:function(a,\\nb,d,e,g){h.registerLine(d,e);h.cmd(a,b,function(a){h.unregisterLine(d);g(a)})},registerLine:function(a,b){if(e[a])throw Error(a+\\\" already registered\\\");e[a]=b},unregisterLine:function(a){delete e[a]},register:function(a,c){if(b[a])throw Error(a+\\\" already registered\\\");b[a]=c},unregister:function(a){delete b[a]},isBusy:function(){return void 0!==d}};return h}\");\n\u0010Modules.addCached(\"EspruinoWiFi\",\"function v(a){var b=a.indexOf(\\\":\\\");if(0>b)return a;var d=a.substring(5,b).split(\\\",\\\");d[1]|=0;var c=a.length-(b+1);if(c>=d[1])return f[d[0]]+=a.substr(b+1,d[1]),a.substr(b+d[1]+1);f[d[0]]+=a.substr(b+1,c);return\\\"+IPD,\\\"+d[0]+\\\",\\\"+(d[1]-c)+\\\":\\\"}function n(a,b){if(b)return a(b);c.cmd(\\\"AT+CWMODE=\\\"+g+\\\"\\\\r\\\\n\\\",1E3,function(b){\\\"no change\\\"!=b&&\\\"OK\\\"!=b&&\\\"WIFI DISCONNECT\\\"!=b?a(\\\"CWMODE failed: \\\"+(b?b:\\\"Timeout\\\")):a(null)})}function h(a){e[a[0]]=\\\"Wait\\\"==e[a[0]]?!0:\\\"Accept\\\"}function k(a){e[a[0]]=\\\"\\\"!=f[a[0]]?\\n\\\"DataClose\\\":void 0}function p(a,b){var d=0==g;g|=a;d?(q.setup(115200,{rx:A3,tx:A2}),c=require(\\\"AT\\\").connect(q),c.register(\\\"+IPD\\\",v),c.registerLine(\\\"0,CONNECT\\\",h),c.registerLine(\\\"1,CONNECT\\\",h),c.registerLine(\\\"2,CONNECT\\\",h),c.registerLine(\\\"3,CONNECT\\\",h),c.registerLine(\\\"4,CONNECT\\\",h),c.registerLine(\\\"0,CLOSED\\\",k),c.registerLine(\\\"1,CLOSED\\\",k),c.registerLine(\\\"2,CLOSED\\\",k),c.registerLine(\\\"3,CLOSED\\\",k),c.registerLine(\\\"4,CLOSED\\\",k),exports.at=c,require(\\\"NetworkJS\\\").create(t),c.cmd(\\\"\\\\r\\\\nAT+RST\\\\r\\\\n\\\",1E4,function l(a){if(\\\"ready\\\"==\\na||\\\"Ready.\\\"==a)setTimeout(function(){c.cmd(\\\"ATE0\\\\r\\\\n\\\",1E3,function w(a){if(\\\"ATE0\\\"==a)return w;\\\"OK\\\"==a?c.cmd(\\\"AT+CIPMUX=1\\\\r\\\\n\\\",1E3,function(a){\\\"OK\\\"!=a?b(\\\"CIPMUX failed: \\\"+(a?a:\\\"Timeout\\\")):n(b)}):b(\\\"ATE0 failed: \\\"+(a?a:\\\"Timeout\\\"))})},500);else if(void 0===a)b(\\\"No 'ready' after AT+RST\\\");else return l}),digitalWrite(x,1),digitalWrite(r,1)):n(b)}function u(a){(g&=~a)?n(function(){},null):(q.removeAllListeners(),c=void 0,exports.at=void 0,digitalWrite(r,0),e=[])}var x=A13,r=A14,q=Serial2;digitalWrite(r,\\n0);var y=[\\\"open\\\",\\\"wep\\\",\\\"wpa_psk\\\",\\\"wpa2_psk\\\",\\\"wpa_wpa2_psk\\\"],g=0,c,e=[],f=[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\"],t={create:function(a,b){if(!c)return-1;if(void 0===a){var d=5;e[d]=\\\"Wait\\\";f[d]=\\\"\\\";c.cmd(\\\"AT+CIPSERVER=1,\\\"+b+\\\"\\\\r\\\\n\\\",1E4,function(a){\\\"OK\\\"==a?e[d]=!0:(e[d]=void 0,setTimeout(function(){throw Error(\\\"CIPSERVER failed (\\\"+(a?a:\\\"Timeout\\\")+\\\")\\\");},0))});return 5}for(d=0;void 0!==e[d];)d++;if(5<=d)return-7;e[d]=\\\"Wait\\\";f[d]=\\\"\\\";c.cmd(\\\"AT+CIPSTART=\\\"+d+',\\\"TCP\\\",'+JSON.stringify(a)+\\\",\\\"+b+\\\"\\\\r\\\\n\\\",1E4,function(a){\\\"OK\\\"!=a&&(e[d]=\\n-6)});return d},close:function(a){\\\"Wait\\\"==e[a]?e[a]=\\\"WaitClose\\\":void 0!==e[a]&&(0>e[a]?e[a]=void 0:c.cmd((5==a?\\\"AT+CIPSERVER=0\\\":\\\"AT+CIPCLOSE=\\\"+a)+\\\"\\\\r\\\\n\\\",1E3,function(b){e[a]=void 0}))},accept:function(a){for(a=0;5>a;a++)if(\\\"Accept\\\"==e[a])return e[a]=!0,a;return-1},recv:function(a,b){if(f[a]){if(f[a].length>b){var d=f[a].substr(0,b);f[a]=f[a].substr(b)}else d=f[a],f[a]=\\\"\\\",\\\"DataClose\\\"==e[a]&&(e[a]=void 0);return d}return 0>e[a]?e[a]:e[a]?\\\"\\\":-1},send:function(a,b){if(!c)return-1;if(c.isBusy()||\\\"Wait\\\"==\\ne[a])return 0;if(0>e[a])return e[a];if(!e[a])return-1;c.cmd(\\\"AT+CIPSEND=\\\"+a+\\\",\\\"+b.length+\\\"\\\\r\\\\n\\\",1E4,function m(l){if(\\\"OK\\\"==l)return c.register(\\\"> \\\",function(){c.unregister(\\\"> \\\");c.write(b);return\\\"\\\"}),m;if(l==\\\"Recv \\\"+b.length+\\\" bytes\\\")return m;\\\"SEND OK\\\"==l?(\\\"WaitClose\\\"==e[a]&&t.close(a),e[a]=!0):(e[a]=void 0,c.unregister(\\\"> \\\"))});e[a]=\\\"Wait\\\";return b.length}};exports.connect=function(a,b,d){var e=\\\"\\\";d=d||function(){};void 0!==b.password&&(e=b.password);p(1,function(b){if(b)return d(b);c.cmd(\\\"AT+CWJAP=\\\"+\\nJSON.stringify(a)+\\\",\\\"+JSON.stringify(e)+\\\"\\\\r\\\\n\\\",2E4,function z(a){if(0<=[\\\"WIFI DISCONNECT\\\",\\\"WIFI CONNECTED\\\",\\\"WIFI GOT IP\\\",\\\"+CWJAP:1\\\"].indexOf(a))return z;\\\"OK\\\"!=a?setTimeout(d,0,\\\"WiFi connect failed: \\\"+(a?a:\\\"Timeout\\\")):setTimeout(d,0,null)})})};exports.disconnect=function(){u(1)};exports.getIP=function(a){var b={};c.cmd(\\\"AT+CIFSR\\\\r\\\\n\\\",1E3,function m(c){if(void 0===c)a(\\\"Timeout\\\");else{if(\\\"+CIFSR:STAIP\\\"==c.substr(0,12))b.ip=c.slice(14,-1);else if(\\\"+CIFSR:STAMAC\\\"==c.substr(0,13))b.mac=c.slice(15,-1);else if(\\\"OK\\\"==\\nc){a(null,b);return}return m}})};exports.startAP=function(a,b,d){b=b||{};if(!b.password||8>b.password.length)throw Error(\\\"Password must be at least 8 characters\\\");var e=b.password?\\\"3\\\":\\\"0\\\";if(b.authMode&&(e={open:0,wpa:2,wpa2:3,wpa_wpa2:4}[b.authMode],void 0===e))throw Error(\\\"Unknown authMode \\\"+b.authMode);void 0===b.channel&&(b.channel=5);p(2,function(f){if(f)return d(f);c.cmd(\\\"AT+CWSAP=\\\"+JSON.stringify(a)+\\\",\\\"+JSON.stringify(b.password)+\\\",\\\"+b.channel+\\\",\\\"+e+\\\"\\\\r\\\\n\\\",5E3,function(a){\\\"OK\\\"!=a?d(\\\"CWSAP failed: \\\"+\\n(a?a:\\\"Timeout\\\")):d(null)})})};exports.stopAP=function(){u(2)};exports.scan=function(a){var b=[];p(1,function(d){if(d)return a(d);c.cmdReg(\\\"AT+CWLAP\\\\r\\\\n\\\",5E3,\\\"+CWLAP:\\\",function(a){a=a.slice(8,-1).split(\\\",\\\");b.push({ssid:JSON.parse(a[1]),authMode:y[a[0]],rssi:parseInt(a[2]),mac:JSON.parse(a[3]),channel:JSON.parse(a[4])})},function(c){a(null,b)})})};exports.debug=function(){return{wifiMode:g,socks:e,sockData:f}}\");\n\u0010Modules.addCached(\"DS18B20\",\"function c(b,a){this.bus=b;void 0===a?this.sCode=this.bus.search()[0]:parseInt(a).toString()==a&&0<=a&&126>=a?this.sCode=this.bus.search()[a]:this.sCode=a;if(!this.sCode)throw Error(\\\"No DS18B20 found\\\");this.type=parseInt(this.sCode[0]+this.sCode[1])}c.prototype._r=function(){var b=this.bus;b.select(this.sCode);b.write(190);return b.read(9)};c.prototype._w=function(b,a,c){var f=this.bus;f.select(this.sCode);f.write([78,b,a,c]);f.select(this.sCode);f.write(72);f.reset()};c.prototype.setRes=\\nfunction(b){var a=this._r();b=[31,63,95,127][E.clip(b,9,12)-9];this._w(a[2],a[3],b)};c.prototype.getRes=function(){return[31,63,95,127].indexOf(this._r()[4])+9};c.prototype.isPresent=function(){return-1!==this.bus.search().indexOf(this.sCode)};c.prototype.getTemp=function(b){function a(a){for(var c=a._r(),e=0,d=0;8>d;d++)for(var e=e^c[d],g=0;8>g;g++)e=e>>1^140*(e&1);d=null;e==c[8]&&(d=c[0]+(c[1]<<8),d&32768&&(d-=65536),d/=10==a.type?2:16);b&&b(d);return d}this.bus.select(this.sCode);this.bus.write(68,\\n!0);if(!b)return a(this);setTimeout(a,{9:94,10:188,11:375,12:750}[this.getRes()],this)};c.prototype.searchAlarm=function(){return this.bus.search(236)};c.prototype.setAlarm=function(b,a){b--;0>b&&(b+=256);0>a&&(a+=256);var c=this._r();this._w(a,b,c[4])};exports.connect=function(b,a){return new c(b,a)}\");\n\u0010var DEVICE_ID = \"1234\";\n\u0010var WIFI_NAME = \"Aeris\";\n\u0010var WIFI_OPTIONS = {\u001b\n  password : \"interare!domus42\"\u001b\n};\n\u0010var KNIT_ADDRESS = '192.168.1.64';\n\u0010var KNIT_PORT = 3000;\n\u0010var ow = new OneWire(A0);\n\u0010var sensor;\n\u0010console.log('Connecting to sensor');\n\u0010try {\u001b\n  sensor = require(\"DS18B20\").connect(ow);\u001b\n} catch (e) {\u001b\n  console.log('Unable to connect to sensor \\n', e.message); \u001b\n}\n\u0010console.log('Starting Wifi connection');\n\u0010var wifi = require(\"EspruinoWiFi\");\n\u0010wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {\u001b\n  if (err) {\u001b\n    console.log(\"Wifi Connection error: \"+err);\u001b\n    return;\u001b\n  }\u001b\n  console.log(\"Connected!\");\u001b\n  start();\u001b\n});\n\u0010var http;\n\u0010function start() {\u001b\n  http = require('http');\u001b\n  if (sensor) {\u001b\n    getTemp();\u001b\n    //setInterval(getTemp, 60000);\u001b\n  } else {\u001b\n    // TODO: Report failure to somewhere\u001b\n  }\u001b\n}\n\u0010function getTemp() {\u001b\n  sensor.getTemp(function(temp) {\u001b\n    console.log(\"Temp is \"+temp+\"°C\"); \u001b\n    sendTemp(temp);\u001b\n  });\u001b\n}\n\u0010function sendTemp(temp) {\u001b\n\u001b\n  var postData = {\u001b\n   value: {\u001b\n     temperature: temp,\u001b\n     unit: 'celsius'\u001b\n   },\u001b\n  };\u001b\n\u001b\n  var reqPath= '/api/devices/' + DEVICE_ID;\u001b\n\u001b\n  var req = http.request({\u001b\n    host: KNIT_ADDRESS,\u001b\n    port: KNIT_PORT,\u001b\n    path: reqPath,\u001b\n    method: 'POST',\u001b\n    headers: {\u001b\n      'Content-Type': 'application/json'\u001b\n    }\u001b\n  }, function(res) {\u001b\n    console.log(\"STATUS: \" + res.statusCode);\u001b\n    console.log(\"HEADERS: \" + JSON.stringify(res.headers));\u001b\n    res.setEncoding('utf8');\u001b\n    res.on('data', function(data) {\u001b\n      //console.log(\"HTTP> \"+data);\u001b\n    });\u001b\n    res.on('close', function(data) {\u001b\n      console.log(\"Connection closed\");\u001b\n    });\u001b\n  });\u001b\n  req.on('error', function(e) {\u001b\n    console.log(\"ERROR: problem with request: \" + e.message);\u001b\n  });\u001b\n  req.write(postData);\u001b\n  req.end();\u001b\n}\n\n"
    Splitting at "reset();\n", delay 250
    >>> Sent
    Splitting at "\u0003", delay 250
    Splitting at "\u0003", delay 250
    Disconnect callback...
    WARNING: [notify_warn] Disconnected
    >>> Disconnected
    >>> Connecting...
    ForceThrottle option is set - set Slow Write = true
    [object Object]
    Connected [object Object]
    Found a prompt... great!
    >>> Sending...
    ---> "\u0010console.log(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n"
    >>> Sent
    WARNING: No result found - just got "echo(1)\r\n=undefined\r\n>< << {\"VERSION\":\"1v91\",\"BUILD_DATE\":\"Jan 12 2017\",\"BUILD_TIME\":\"10:55:52\",\"GIT_COMMIT\":\"a6300790b771b7afffdb2bb2d8c5d0607f7977ef\",\"BOARD\":\"ESPRUINOWIFI\",\"CHIP\":\"STM32F411CEU6\",\"CHIP_FAMILY\":\"STM32F4\",\"FLASH\":524288,\"RAM\":131072,\"SERIAL\":\"43001d00-0b513532-39333638\",\"CONSOLE\":\"USB\",\"EXPORTS\":{\"jsvLock\":336089,\"jsvLockAgainSafe\":336075,\"jsvUnLock\":336049,\"jsvSkipName\":184381,\"jsvMathsOp\":141949,\"jsvMathsOpSkipNames\":141995,\"jsvNewFromFloat\":336405,\"jsvNewFromInteger\":336441,\"jsvNewFromString\":339205,\"jsvNewFromBool\":336425,\"jsvGetFloat\":184749,\"jsvGetInteger\":180485,\"jsvGetBool\":185337,\"jspeiFindInScopes\":145525,\"jspReplaceWith\":154073,\"jspeFunctionCall\":150877,\"jspGetNamedVariable\":145585,\"jspGetNamedField\":146857,\"jspGetVarNamedField\":146449,\"jsv"
    Device found (connectionId=3)
    [success] Connected to port /dev/tty.usbmodem1421
    >>> Connected to port /dev/tty.usbmodem1421
    loadModule(DS18B20)
    loadModule(EspruinoWiFi)
    loadModule(http)
     - DS18B20 requires []
     - EspruinoWiFi requires ["AT","NetworkJS"]
       Queueing AT
       Queueing NetworkJS
    ERROR: Not Found
    loadModule(AT)
    loadModule(NetworkJS)
    ERROR: Not Found
    WARNING: [notify_warn] Module http not found
     - AT requires []
    ERROR: Not Found
    ERROR: Not Found
    WARNING: [notify_warn] Module NetworkJS not found
    Received a prompt after sending newline... good!
    >>> Sending...
    ---> "\u0010reset();\n\u0010setTime(1505076833.293);\n\u0010Modules.removeAllCached();\n\u0010Modules.addCached(\"AT\",\"exports.connect=function(l){var m=!1,a=\\\"\\\",d,b={},e={},g=[];l.on(\\\"data\\\",function(f){a+=f;m&&console.log(\\\"] \\\"+JSON.stringify(a)+\\\" <--- \\\"+JSON.stringify(f));\\\"\\\\n\\\"==a[0]&&(a=a.substr(1));if(b){b[\\\">\\\"]&&\\\">\\\"==a[0]&&(a=b[\\\">\\\"](a));for(var c in b)a.substr(0,c.length)==c&&(a=b[c](a))}for(f=a.indexOf(\\\"\\\\r\\\");0<=f;){var k=a.substr(0,f);if(0<k.length){var n=!1;for(c in e)k.substr(0,c.length)==c&&(e[c](k),n=!0);n||d&&d(k)}a=a.substr(f+1);\\\"\\\\n\\\"==a[0]&&(a=a.substr(1));if(a.length&&b)for(c in b[\\\">\\\"]&&\\\">\\\"==\\na[0]&&(a=b[\\\">\\\"](a)),b)a.substr(0,c.length)==c&&(a=b[c](a));f=a.indexOf(\\\"\\\\r\\\")}});var h={debug:function(){m=!0;return{line:a,lineCallback:d,handlers:b,lineHandlers:e,waiting:g}},cmd:function(a,c,b){if(d)g.push([a,c,b]);else if(m&&console.log(\\\"[\\\"+JSON.stringify(a)),l.write(a),c){var e=setTimeout(function(){d=void 0;b&&b()},c),p=function(a){d=void 0;var f;b&&(f=b(a))?(d=p,b=f):clearTimeout(e);void 0===d&&0<g.length&&(a=g.shift(),h.cmd(a[0],a[1],a[2]))};d=p}},write:function(a){l.write(a)},cmdReg:function(a,\\nb,d,e,g){h.registerLine(d,e);h.cmd(a,b,function(a){h.unregisterLine(d);g(a)})},registerLine:function(a,b){if(e[a])throw Error(a+\\\" already registered\\\");e[a]=b},unregisterLine:function(a){delete e[a]},register:function(a,c){if(b[a])throw Error(a+\\\" already registered\\\");b[a]=c},unregister:function(a){delete b[a]},isBusy:function(){return void 0!==d}};return h}\");\n\u0010Modules.addCached(\"EspruinoWiFi\",\"function v(a){var b=a.indexOf(\\\":\\\");if(0>b)return a;var d=a.substring(5,b).split(\\\",\\\");d[1]|=0;var c=a.length-(b+1);if(c>=d[1])return f[d[0]]+=a.substr(b+1,d[1]),a.substr(b+d[1]+1);f[d[0]]+=a.substr(b+1,c);return\\\"+IPD,\\\"+d[0]+\\\",\\\"+(d[1]-c)+\\\":\\\"}function n(a,b){if(b)return a(b);c.cmd(\\\"AT+CWMODE=\\\"+g+\\\"\\\\r\\\\n\\\",1E3,function(b){\\\"no change\\\"!=b&&\\\"OK\\\"!=b&&\\\"WIFI DISCONNECT\\\"!=b?a(\\\"CWMODE failed: \\\"+(b?b:\\\"Timeout\\\")):a(null)})}function h(a){e[a[0]]=\\\"Wait\\\"==e[a[0]]?!0:\\\"Accept\\\"}function k(a){e[a[0]]=\\\"\\\"!=f[a[0]]?\\n\\\"DataClose\\\":void 0}function p(a,b){var d=0==g;g|=a;d?(q.setup(115200,{rx:A3,tx:A2}),c=require(\\\"AT\\\").connect(q),c.register(\\\"+IPD\\\",v),c.registerLine(\\\"0,CONNECT\\\",h),c.registerLine(\\\"1,CONNECT\\\",h),c.registerLine(\\\"2,CONNECT\\\",h),c.registerLine(\\\"3,CONNECT\\\",h),c.registerLine(\\\"4,CONNECT\\\",h),c.registerLine(\\\"0,CLOSED\\\",k),c.registerLine(\\\"1,CLOSED\\\",k),c.registerLine(\\\"2,CLOSED\\\",k),c.registerLine(\\\"3,CLOSED\\\",k),c.registerLine(\\\"4,CLOSED\\\",k),exports.at=c,require(\\\"NetworkJS\\\").create(t),c.cmd(\\\"\\\\r\\\\nAT+RST\\\\r\\\\n\\\",1E4,function l(a){if(\\\"ready\\\"==\\na||\\\"Ready.\\\"==a)setTimeout(function(){c.cmd(\\\"ATE0\\\\r\\\\n\\\",1E3,function w(a){if(\\\"ATE0\\\"==a)return w;\\\"OK\\\"==a?c.cmd(\\\"AT+CIPMUX=1\\\\r\\\\n\\\",1E3,function(a){\\\"OK\\\"!=a?b(\\\"CIPMUX failed: \\\"+(a?a:\\\"Timeout\\\")):n(b)}):b(\\\"ATE0 failed: \\\"+(a?a:\\\"Timeout\\\"))})},500);else if(void 0===a)b(\\\"No 'ready' after AT+RST\\\");else return l}),digitalWrite(x,1),digitalWrite(r,1)):n(b)}function u(a){(g&=~a)?n(function(){},null):(q.removeAllListeners(),c=void 0,exports.at=void 0,digitalWrite(r,0),e=[])}var x=A13,r=A14,q=Serial2;digitalWrite(r,\\n0);var y=[\\\"open\\\",\\\"wep\\\",\\\"wpa_psk\\\",\\\"wpa2_psk\\\",\\\"wpa_wpa2_psk\\\"],g=0,c,e=[],f=[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\"],t={create:function(a,b){if(!c)return-1;if(void 0===a){var d=5;e[d]=\\\"Wait\\\";f[d]=\\\"\\\";c.cmd(\\\"AT+CIPSERVER=1,\\\"+b+\\\"\\\\r\\\\n\\\",1E4,function(a){\\\"OK\\\"==a?e[d]=!0:(e[d]=void 0,setTimeout(function(){throw Error(\\\"CIPSERVER failed (\\\"+(a?a:\\\"Timeout\\\")+\\\")\\\");},0))});return 5}for(d=0;void 0!==e[d];)d++;if(5<=d)return-7;e[d]=\\\"Wait\\\";f[d]=\\\"\\\";c.cmd(\\\"AT+CIPSTART=\\\"+d+',\\\"TCP\\\",'+JSON.stringify(a)+\\\",\\\"+b+\\\"\\\\r\\\\n\\\",1E4,function(a){\\\"OK\\\"!=a&&(e[d]=\\n-6)});return d},close:function(a){\\\"Wait\\\"==e[a]?e[a]=\\\"WaitClose\\\":void 0!==e[a]&&(0>e[a]?e[a]=void 0:c.cmd((5==a?\\\"AT+CIPSERVER=0\\\":\\\"AT+CIPCLOSE=\\\"+a)+\\\"\\\\r\\\\n\\\",1E3,function(b){e[a]=void 0}))},accept:function(a){for(a=0;5>a;a++)if(\\\"Accept\\\"==e[a])return e[a]=!0,a;return-1},recv:function(a,b){if(f[a]){if(f[a].length>b){var d=f[a].substr(0,b);f[a]=f[a].substr(b)}else d=f[a],f[a]=\\\"\\\",\\\"DataClose\\\"==e[a]&&(e[a]=void 0);return d}return 0>e[a]?e[a]:e[a]?\\\"\\\":-1},send:function(a,b){if(!c)return-1;if(c.isBusy()||\\\"Wait\\\"==\\ne[a])return 0;if(0>e[a])return e[a];if(!e[a])return-1;c.cmd(\\\"AT+CIPSEND=\\\"+a+\\\",\\\"+b.length+\\\"\\\\r\\\\n\\\",1E4,function m(l){if(\\\"OK\\\"==l)return c.register(\\\"> \\\",function(){c.unregister(\\\"> \\\");c.write(b);return\\\"\\\"}),m;if(l==\\\"Recv \\\"+b.length+\\\" bytes\\\")return m;\\\"SEND OK\\\"==l?(\\\"WaitClose\\\"==e[a]&&t.close(a),e[a]=!0):(e[a]=void 0,c.unregister(\\\"> \\\"))});e[a]=\\\"Wait\\\";return b.length}};exports.connect=function(a,b,d){var e=\\\"\\\";d=d||function(){};void 0!==b.password&&(e=b.password);p(1,function(b){if(b)return d(b);c.cmd(\\\"AT+CWJAP=\\\"+\\nJSON.stringify(a)+\\\",\\\"+JSON.stringify(e)+\\\"\\\\r\\\\n\\\",2E4,function z(a){if(0<=[\\\"WIFI DISCONNECT\\\",\\\"WIFI CONNECTED\\\",\\\"WIFI GOT IP\\\",\\\"+CWJAP:1\\\"].indexOf(a))return z;\\\"OK\\\"!=a?setTimeout(d,0,\\\"WiFi connect failed: \\\"+(a?a:\\\"Timeout\\\")):setTimeout(d,0,null)})})};exports.disconnect=function(){u(1)};exports.getIP=function(a){var b={};c.cmd(\\\"AT+CIFSR\\\\r\\\\n\\\",1E3,function m(c){if(void 0===c)a(\\\"Timeout\\\");else{if(\\\"+CIFSR:STAIP\\\"==c.substr(0,12))b.ip=c.slice(14,-1);else if(\\\"+CIFSR:STAMAC\\\"==c.substr(0,13))b.mac=c.slice(15,-1);else if(\\\"OK\\\"==\\nc){a(null,b);return}return m}})};exports.startAP=function(a,b,d){b=b||{};if(!b.password||8>b.password.length)throw Error(\\\"Password must be at least 8 characters\\\");var e=b.password?\\\"3\\\":\\\"0\\\";if(b.authMode&&(e={open:0,wpa:2,wpa2:3,wpa_wpa2:4}[b.authMode],void 0===e))throw Error(\\\"Unknown authMode \\\"+b.authMode);void 0===b.channel&&(b.channel=5);p(2,function(f){if(f)return d(f);c.cmd(\\\"AT+CWSAP=\\\"+JSON.stringify(a)+\\\",\\\"+JSON.stringify(b.password)+\\\",\\\"+b.channel+\\\",\\\"+e+\\\"\\\\r\\\\n\\\",5E3,function(a){\\\"OK\\\"!=a?d(\\\"CWSAP failed: \\\"+\\n(a?a:\\\"Timeout\\\")):d(null)})})};exports.stopAP=function(){u(2)};exports.scan=function(a){var b=[];p(1,function(d){if(d)return a(d);c.cmdReg(\\\"AT+CWLAP\\\\r\\\\n\\\",5E3,\\\"+CWLAP:\\\",function(a){a=a.slice(8,-1).split(\\\",\\\");b.push({ssid:JSON.parse(a[1]),authMode:y[a[0]],rssi:parseInt(a[2]),mac:JSON.parse(a[3]),channel:JSON.parse(a[4])})},function(c){a(null,b)})})};exports.debug=function(){return{wifiMode:g,socks:e,sockData:f}}\");\n\u0010Modules.addCached(\"DS18B20\",\"function c(b,a){this.bus=b;void 0===a?this.sCode=this.bus.search()[0]:parseInt(a).toString()==a&&0<=a&&126>=a?this.sCode=this.bus.search()[a]:this.sCode=a;if(!this.sCode)throw Error(\\\"No DS18B20 found\\\");this.type=parseInt(this.sCode[0]+this.sCode[1])}c.prototype._r=function(){var b=this.bus;b.select(this.sCode);b.write(190);return b.read(9)};c.prototype._w=function(b,a,c){var f=this.bus;f.select(this.sCode);f.write([78,b,a,c]);f.select(this.sCode);f.write(72);f.reset()};c.prototype.setRes=\\nfunction(b){var a=this._r();b=[31,63,95,127][E.clip(b,9,12)-9];this._w(a[2],a[3],b)};c.prototype.getRes=function(){return[31,63,95,127].indexOf(this._r()[4])+9};c.prototype.isPresent=function(){return-1!==this.bus.search().indexOf(this.sCode)};c.prototype.getTemp=function(b){function a(a){for(var c=a._r(),e=0,d=0;8>d;d++)for(var e=e^c[d],g=0;8>g;g++)e=e>>1^140*(e&1);d=null;e==c[8]&&(d=c[0]+(c[1]<<8),d&32768&&(d-=65536),d/=10==a.type?2:16);b&&b(d);return d}this.bus.select(this.sCode);this.bus.write(68,\\n!0);if(!b)return a(this);setTimeout(a,{9:94,10:188,11:375,12:750}[this.getRes()],this)};c.prototype.searchAlarm=function(){return this.bus.search(236)};c.prototype.setAlarm=function(b,a){b--;0>b&&(b+=256);0>a&&(a+=256);var c=this._r();this._w(a,b,c[4])};exports.connect=function(b,a){return new c(b,a)}\");\n\u0010var DEVICE_ID = \"1234\";\n\u0010var WIFI_NAME = \"Aeris\";\n\u0010var WIFI_OPTIONS = {\u001b\n  password : \"interare!domus42\"\u001b\n};\n\u0010var KNIT_ADDRESS = '192.168.1.64';\n\u0010var KNIT_PORT = 3000;\n\u0010var ow = new OneWire(A0);\n\u0010var sensor;\n\u0010console.log('Connecting to sensor');\n\u0010try {\u001b\n  sensor = require(\"DS18B20\").connect(ow);\u001b\n} catch (e) {\u001b\n  console.log('Unable to connect to sensor \\n', e.message); \u001b\n}\n\u0010console.log('Starting Wifi connection');\n\u0010var wifi = require(\"EspruinoWiFi\");\n\u0010wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {\u001b\n  if (err) {\u001b\n    console.log(\"Wifi Connection error: \"+err);\u001b\n    return;\u001b\n  }\u001b\n  console.log(\"Connected!\");\u001b\n  start();\u001b\n});\n\u0010var http;\n\u0010function start() {\u001b\n  http = require('http');\u001b\n  if (sensor) {\u001b\n    getTemp();\u001b\n    //setInterval(getTemp, 60000);\u001b\n  } else {\u001b\n    // TODO: Report failure to somewhere\u001b\n  }\u001b\n}\n\u0010function getTemp() {\u001b\n  sensor.getTemp(function(temp) {\u001b\n    console.log(\"Temp is \"+temp+\"°C\"); \u001b\n    sendTemp(temp);\u001b\n  });\u001b\n}\n\u0010function sendTemp(temp) {\u001b\n\u001b\n  var postData = {\u001b\n   value: {\u001b\n     temperature: temp,\u001b\n     unit: 'celsius'\u001b\n   },\u001b\n  };\u001b\n\u001b\n  var reqPath= '/api/devices/' + DEVICE_ID;\u001b\n\u001b\n  var req = http.request({\u001b\n    host: KNIT_ADDRESS,\u001b\n    port: KNIT_PORT,\u001b\n    path: reqPath,\u001b\n    method: 'POST',\u001b\n    headers: {\u001b\n      'Content-Type': 'application/json'\u001b\n    }\u001b\n  }, function(res) {\u001b\n    console.log(\"STATUS: \" + res.statusCode);\u001b\n    console.log(\"HEADERS: \" + JSON.stringify(res.headers));\u001b\n    res.setEncoding('utf8');\u001b\n    res.on('data', function(data) {\u001b\n      //console.log(\"HTTP> \"+data);\u001b\n    });\u001b\n    res.on('close', function(data) {\u001b\n      console.log(\"Connection closed\");\u001b\n    });\u001b\n  });\u001b\n  req.on('error', function(e) {\u001b\n    console.log(\"ERROR: problem with request: \" + e.message);\u001b\n  });\u001b\n  req.write(postData);\u001b\n  req.end();\u001b\n}\n\n"
    Splitting at "reset();\n", delay 250
    >>> Sent
    Splitting at "\u0003", delay 250
    Splitting at "\u0003", delay 250
    
  • in Pico / Wifi / Original Espruino
    Avatar for KevinJ

    Simple programs such as blink seem to transfer and run just fine, but I'm working with some Wifi and Http code that is significantly longer and it doesn't seem to transfer correctly. Log is below. The hardware is relatively new, but it worked correctly for about a day.

    Steps I've tried so far to resolve:

    • Unplugged it and plugged it back in again (yea, I worked in IT, gotta start there)
    • Used another USB cable
    • Turned on "Throttle Send" in the settings
    • Commented out large chunks, and the error moved to another line

    Environment:

    • Espruino Web IDE used as Chrome App
    • Mac OSX 10.12.6

      >
      Connected
      >echo(1)
      =undefined
      >< << {"VERSION":"1v91","BUILD_DATE":"Jan 12 2017","BUILD_TIME":"10:55:52","GIT_COMMIT":"a6300790b771b7afffdb2bb2d8c5d0607f7977ef","BOARD":"ESPRUINOWIFI","CHIP":"STM32F411CEU6","CHIP_FAMILY":"STM32F4","FLASH":524288,"RAM":131072,"SERIAL":"43001d00-0b513532-39333638","CONSOLE":"USB","EXPORTS":{"jsvLock":336089,"jsvLockAgainSafe":336075,"jsvUnLock":336049,"jsvSkipName":184381,"jsvMathsOp":141949,"jsvMathsOpSkipNames":141995,"jsvNewFromFloat":336405,"jsvNewFromInteger":336441,"jsvNewFromString":339205,"jsvNewFromBool":336425,"jsvGetFloat":184749,"jsvGetInteger":180485,"jsvGetBool":185337,"jspeiFindInScopes":145525,"jspReplaceWith":154073,"jspeFunctionCall":150877,"jspGetNamedVariable":145585,"jspGetNamedField":146857,"jspGetVarNamedField":146449,"jsvNewWithFlags":336245}} >> >
      >
      =undefined
      >
      _____                 _
      |   __|___ ___ ___ _ _|_|___ ___
      |   __|_ -| . |  _| | | |   | . |
      |_____|___|  _|_| |___|_|_|_|___|
            |_| http://espruino.com
      1v91 Copyright 2016 G.Williams
      >Connecting to sensor
      >Starting Wifi connection
      Uncaught SyntaxError: Got '(' expected ','
      at line 1 col 22
      function start(equire('http');
                       ^
      ERROR: Prompt not detected - upload failed. Trying to recover...
      =undefined
      >echo(1)
      =undefined
      Connected!
      Uncaught Error: Function "start" not found!
      at line 6 col 3
      start() 
      
      // Constants
      var DEVICE_ID = "1234";
      var WIFI_NAME = "*********";
      var WIFI_OPTIONS = {
      password : "*********"
      };
      var SERVER_ADDRESS = '*********';
      var SERVER_PORT = 3000;
      
      // Connect to Sensor
      var ow = new OneWire(A0);
      var sensor;
      console.log('Connecting to sensor');
      try {
      sensor = require("DS18B20").connect(ow);
      } catch (e) {
      console.log('Unable to connect to sensor \n', e.message); 
      }
      
      // Connect to Wifi
      console.log('Starting Wifi connection');
      var wifi = require("EspruinoWiFi");
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
      if (err) {
      console.log("Wifi Connection error: "+err);
      return;
      }
      console.log("Connected!");
      start();
      });
      
      var http;
      function start() {
      http = require('http');
      if (sensor) {
      getTemp();
      //setInterval(getTemp, 60000);
      } else {
      // TODO: Report failure to somewhere
      }
      }
      
      function getTemp() {
      sensor.getTemp(function(temp) {
      console.log("Temp is "+temp+"°C"); 
      sendTemp(temp);
      });
      }
      
      function sendTemp(temp) {
      
      var postData = {
      value: {
       temperature: temp,
       unit: 'celsius'
      },
      };
      
      var reqPath= '/api/devices/' + DEVICE_ID;
      
      var req = http.request({
      host: SERVER_ADDRESS,
      port: SERVER_PORT,
      path: reqPath,
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      }
      }, function(res) {
      console.log("STATUS: " + res.statusCode);
      console.log("HEADERS: " + JSON.stringify(res.headers));
      res.setEncoding('utf8');
      res.on('data', function(data) {
        console.log("HTTP> "+data);
      });
      res.on('close', function(data) {
        console.log("Connection closed");
      });
      });
      req.on('error', function(e) {
      console.log("ERROR: problem with request: " + e.message);
      });
      req.write(postData);
      req.end();
      }
      
      
      
Actions