-
-
-
The problem never went away on my computer.
Its running windows 8.1 64bit, 4 cores, 8gb ram, connected over USB.- tried to give it more time for reading(up to 10 secs), did not help.
- added timeout in env.js before calling core.utils.execute Expr.., did not help
- reading process.env from terminalwindow always works fine
In log I see, process.env-object stops somewhere in exports, like this
No result found - just got "echo(0);\r\n<<<<<{\"VERSION\":\"1v72\",\"BUILD_DATE\":\"Dec 24 2014\",\"BUILD_TIME\":\"12:10:46\",\"GIT_COMMIT\":\"cca740699928e7f5ee1cee62e43299e19b33f10f\",\"BOARD\":\"ESPRUINOBOARD\",\"CHIP\":\"STM32F103RCT6\",\"CHIP_FAMILY\":\"STM32F1\",\"FLASH\":262144,\"RAM\":49152,\"SERIAL\":\"33ffd905-41573033-07710743\",\"CONSOLE\":\"USB\",\"EXPORT\":[\"jsvLock,jsvLockAgain,jsvUnLock,jsvMathsOp,jsvMathsOpSkipNames,jsvNewFromFloat,jsvNewFromInteger,jsvNewFromString,jsvNewFromBool,jsvGetFloat,jsvGetInteger,jsvGetBool,jspeiFindInScopes,jspReplaceW" - tried to give it more time for reading(up to 10 secs), did not help.
-
-
To get a better understanding, I tried to get promise-simple in jsfiddle.
My idea was to use something like this.console.log(new Date()); function t(d) { var pd = Promise.defer(); setTimeout(function() {pd.resolve("first" + d);}, d*1000); return pd; }; Promise.when(t(1),t(2)).then(function(results) {console.log(new Date(),results);});
In this example function in then is called after having finished t(1) and t(2).
In log you can see delay of 2 secs for the slower function.
To get this running, I had to remove .resolve() for isPromise-part in when function. This problem exists in all sources and examples I found in github.
Therefore I'm unsure whether this is a correct solution. At least it does what I expect to do. -
I love the option to precompile functions.
Therefore I copied the js_compiler branch of tools to my computer.
After doing some minor changes, like adding script tag, changing env.getBoardData, I got the compiler running.
Since I don't have tools(and knowledge) to compile firmware, testing was like swimming without water.
Anyway, I would like to add some comments.- I would like to get an additional window , to switch between JS, Blockly and Assembler source. Compiler could send compiled source to Assembler window.
- If you have 2 functions in source, both are compiled but for 2nd JS-source is still sent to Espruino board
- Get exports directly from process.env could become a problem, the more entrypoints you have. Would it be possible, to read them similiar to Board Info from your server ?
- Enable handling of comments in assembler source, and add more comments to compiler. This would be a big help for understanding, and may be optimizing.
- Add a command to install binaries from SD-card.
- Extend projects to handle assembler modules. I could do this, as long as I get some guidelines. Simple first step could be to add read and write function for asselmbler in projects plugin.
- I'm pretty sure, it will take a lot of time to get a full blown up compiler. As long as we don't have this, it would help to get guidelines for implementing capable functions.
Christmas is gone, but sometimes wishes come true later too.....
- I would like to get an additional window , to switch between JS, Blockly and Assembler source. Compiler could send compiled source to Assembler window.
-
Sorry, I forgot to add a link to Espruino module.
This is done now. -
In this small project, a HC-SR04 is used to support simple gestures.
There is already some information around ST04 in Espruino Documentation
First of all an gesture object needs to be createdvar g = new gesture(A0,A1); //for more information about pins, take a look at http://www.espruino.com/HC-SR04
Next the distance from SR04 is splitted into named areas.
g.addArea("bottom",10,20); //First parameter is name of the area, next are start and end of area in cm g.addArea("middle",30,40); g.addArea("top",50,60);
Last not least assign callbacks for each type of gesture, which returns area, type of event and distance from SR04
g.setCallback("enter",function(a,t,d){console.log(a,t,d);}); g.setCallback("leave",function(a,t,d){console.log(a,t,d);}); g.setCallback("click",function(a,t,d){console.log(a,t,d);}); g.setCallback("move",function(a,t,d,p){console.log(a,t,d,p);});
Simply test this by moving your hand above SR04.
enter is fired after moving the hand into an area
leave is fired after leaving an area in whatever direction
click is fired if entering and leaving happen for the same are
move is fired if your hand moves inside an area and returns one more parameter, giving position in area in percent.
Some training will help to move your hand correctly inside an area, for example to hold your fingers close to each other finger(including thumb :-). For staying inside an area a coloured piece of paper will be helpfulAttached code gives the source for gesture-object.
-
I'm using flat assembler from Thomasz Grysztar.
This was the only free assembler I found for ARM supporting thumb and running on windows.
It creates a bin-file which is used to upload binary data to Espruino.
My sources are short, using pc-relative adressing, so I don't need linking.
There is another file with extension .fas, but I don't find a tool to interpret this. -
As mentioned in previous post, this post gives more information about loading an assembler based module.
var asm = require("ASM"); asm.setup(true); asm.loadLibrary({ varName:"Flash", fileName:"node_binaries/FLASH.BIN", functions:[ {name:"read",format:"int(int)"}, {name:"unlock",format:"void()"}, {name:"write",format:"void(int,int)"}, {name:"erase",format:"void(int)"}, {name:"copyMem",format:"void(int,int,int)"}, {name:"pageSafe",format:"int(int)"} ] }); console.log(asm.listBinaries());
A binary file is loaded from fileName and creates an object named by varName.
This holds functions given by functions array.
Flash.read(adr) // returns an int-value from adr
Flash.unlock // unlocks flash memory, so you can change values
Flash.write(adr,value) // writes value to adr
Flash.erase(adr) // erases fullpage starting at adr
Flash.copyMem(source,destination,length) //copys from "length" bytes from source to destination
Flash.pageSafe(adr) // checks page for safe writing, returns 0 if safeThe assembly file holds a list of branches on top like this (see attached ASM file)
thumb; ;jump table for functions in this library b read ;Flash.read(adr) adr is word aligned (word size 4 bytes) b unlock ;Flash.unlock() b write ;Flash.write(adr,val) adr is word aligned .....
An example, how this can be used is this:
console.log(asm.listBinaries()); console.log("pageSafe",Flash.pageSafe(adr)); console.log("read (0x0803E000):",Flash.read(adr).toString(16)); Flash.unlock(); console.log("unlocked"); Flash.write(adr,0xFFFFFFFE); console.log("new value (-2) written"); console.log("read new value:",Flash.read(adr).toString(16)); Flash.copyMem(adr,adr+16,4); console.log("copyMem done"); console.log("read target",Flash.read(adr+16).toString(16)); console.log("pageSafe, (should be <> 0):",Flash.pageSafe(adr).toString(16)); Flash.erase(adr); console.log("erased"); console.log("pageSafe, should be 0:",Flash.pageSafe(adr).toString(16));
BTW, I had some experience with assembler many years ago. This is my first attempt in ARM assembler, any hint is welcome.
-
For some time now, Espruino supports inline assembler.
To get some experience, I created a replacement for STM32F1 Flash Memory module.
Idea was to have a binary file on SD which is loaded at runtime which would replace Gordons module.
First a new module had to be created which supports loading binarys, please see attached ASM-module.
Commands are:
var asm = require("ASM") //loads module
asm.setup(listON) // if true creates a list of loaded assembler functions, used to safe some memory)
asm.listBinaries() // if setup with true, list all loaded functions
asm.loadArray(varName,format,arr) //creates a function named by varName, using format to describe in/out values and is given by binary in arr
asm.loadSD(varName,format,fileName) //loads a binary file given by fileName, from SD-card, creates a function named by varName, using format to describe in/out values
asm.loadLibrary(lib) // loads a library of functions.
Next post will give a description about lib object for the Flash assembler module. -
-
I have a ILI9341_extended module, including a tiny window implementation.
setRect defines the Rect, which is used for reading and writing.int(int,int,int) [0xBFE1,0x08C0,0x0889,0x08D2,0x02C0,0xEA4F,0x1141,0x4408, 0x4410,0x4601,0xBFE1,0x0200,0x0A09,0x4408,0xF64F,0x71FF, 0xEA00,0x0001,0x4770]
To get it running, you need attached module and the assembler part loaded using the name ILIcalc. Please see http://www.espruino.com/Assembler for more information.
-
One more option could be to use soft SPI, so you can use any pin of your choice.
See http://www.espruino.com/Reference#SPI for more information. -
Some time ago I played around the ILI9341 and added a lot of functions.
GetPixel is done by this, and returns an array with r/g/b values.getPixel = function(x,y){ var c,z = 0xff; setRect(x,y,x+1,y+1); writeCMD(0x2E); dc.write(1); spi.send(z); var zzz = new Uint8Array([0,0,0]); c = spi.send(zzz); ce.write(1); return c; }
To read colors of a rect would be very timeconsuming. Translating the RGB-Array to a color used for ILI9341 takes a lot of time. Some lines in assembler speeded it up, but its still slow. I don't have a tutorial for that, could only send sources, if somebody is interested.
-
-
-
Just seen in another conversation, you are working to support ESP8266.
Please take care to new versions of firmware.
There are some interesting commands and changes:- commands need to be followed by /r/n, in older version /r only worked fine
- AT+CIUPDATE is a command to update firmware from a cloud, if modul is connected to wifi
- ATE0 switches echo off and ATE1 switches it on again. This can help, you don't have to skip echo anymore
Another new version, which I cannot get running is V0.922 which adds AT commands to change baudrate, changing default from 115200 to 9600 same time. There is another command for watchdog handling, but as said before I didn' get it running reliably.
- commands need to be followed by /r/n, in older version /r only worked fine
-
-
-
Take a look to this:
http://www.espruino.com/Reference#l_process_memory -
Finally I got a first version up and running (at least in my environment) which
- initializes ESP8266
- connects to wireless
- gets IP adress
- reads html from a server
listens to a port
To get it running, you have to change mySSID and myPassWD in attached code.
Give it some time, about 20 secs, and you should then get:
>echo(0);
=undefined
init true
connect:true
getIP: true 192.168.1.2 IP in your network can be different
readUrl: true Copyright.... source of servo.js
....
***} ***
Simple test for listening is to open a browser and open "http://192.168.1.2:88?hugo=27
then you should get a line :
listen: /?hugo=27function ESP8266(s,bd,rx,tx){ var sp = s, rdata = "", wText = "",cb,timr,command = "",me = this; me.dbg = false; sp.setup(bd,{rx:rx,tx:tx}); function sendCommandWaitFor(cmd,waitText,waitFor,callback,skipCommand){ var rdata = '', timr,scmd = 'AT+' + cmd + '\r',p; timr = setTimeout(function(){ sp.removeAllListeners('data'); callback(false,rdata); },waitFor); sp.on('data',function(d){ rdata += d; if(skipCommand){ p = rdata.indexOf(scmd + '\r\n'); if(p >= 0){ rdata = rdata.substr(p + scmd.length + 2); } } if(rdata.indexOf(waitText) >=0){ clearTimeout(timr); sp.removeAllListeners('data'); callback(true,rdata); } }); sp.print(scmd); } function sendCommandWait(cmd,waitFor,callback){ sp.print('AT+' + cmd + '\r'); setTimeout(function(){ callback(true,""); }); } function connect(ssid,passwd,callback){ sendCommandWait('CWMODE=1',1000,function(f,d){ sendCommandWaitFor('CWJAP="' + ssid + '","' +passwd + '"','OK',5000,function(f,d){ setTimeout(function(){ if(f){sendCommandWait('CIPMUX=0',1000,callback);} else{callback(false,d);} },5000); }); }); } function getIP(callback){ sendCommandWaitFor("CIFSR","\r\n",2000,callback,true); } function init(callback){ sendCommandWaitFor('RST','ready',5000,function(d,f){callback(d,f);}); } function readUrl(host,adr,port,callback){ var cmd,rdata,timr,p; sendCommandWaitFor('CIPSTART="TCP","' + host + '",' + port,'Linked',1000, function(f,d){ if(f){ cmd ='GET ' + adr + ' HTTP/1.0\r\nHost:' + host + '\r\n\r\n'; sendCommandWaitFor('CIPSEND=' + cmd.length,'>',10000,function(f,d){ timr = setTimeout(function(){ sp.removeAllListeners('data'); callback(false,rdata); },10000); sp.on('data',function(d){ rdata += d; p = rdata.indexOf("Unlink\r\n"); if(p >= 0){ sp.removeAllListeners('data'); clearTimeout(timr); callback(f,extractData(rdata)); } }); sp.print(cmd); }); } }); } function extractData(d){ var p,r = "",l; p = d.indexOf('+IPD,'); while(p >= 0){ d = d.substr(p + 5); p = d.indexOf(':'); r += d.substr(p + 1,parseInt(d.substr(0,p),10)); p = d.indexOf('+IPD,'); } p = r.indexOf("Content-Length"); l = parseInt(r.substr(p,r.substr(p).indexOf('\r\n')).split(":")[1],10); r = r.substr(r.length - l); return r; } function extractListen(d){ var p,r = ""; p = d.indexOf("+IPD,"); if(p >= 0){ r = d.substr(p).split(" ")[1]; } return r; } function listen(port,handler){ var rdata = "",p,q; sendCommandWait("CIPMUX=1",1000,function(f,d){ sendCommandWaitFor("CIPSERVER=1," + port,'OK',2000,function(d,f){ if(d){ sp.on('data',function(d){ rdata += d; p = rdata.indexOf("\r\n"); if(p >= 0){ q = extractListen(rdata.substr(0,p)); if(q !== ""){ handler(q);} rdata = rdata.substr(p + 2); } }); } }); }); } me.connect = connect; me.getIP = getIP; me.init = init; me.readUrl = readUrl; me.listen = listen; } var esp = new ESP8266(Serial4,115200,C11,C10); var mySSID = "changeThis", myPassWD = "changeThis"; esp.init(function(f,d){ console.log("init",f); esp.connect(mySSID,myPassWD,function(f,d){ console.log("connect:",f); esp.getIP(function(d,f){ console.log("getIP:",d,f); //esp.readUrl("192.168.1.3","/Espruino/test.htm",80,function(f,d){ esp.readUrl("http://www.espruino.com","/modules/servo.js",80,function(f,d){ console.log("readUrl:",f,d); esp.listen(88,function(d){console.log("listen:",d);}); }); }); }); });
- initializes ESP8266
-
lowercase helped in (2nd version), thanks
host="espruino.com" and adr="/modules/servo.js"
returned an 301 (object moved permanently)host="http://www.espruino.com" and adr="/modules/servo.js"
made it
why in .... is www. missing in 2nd option ? In editing I see it, but in forum its missing.
One more try it should be w w w.espruino.com -
Hello Gordon,
just tried it with my own server (http://www.jumware.com) and got it working with this:
cmd = 'GET ' + adr + ' HTTP/1.0\r\n Host:' + host + '\r\n\r\n';
where host="JUMWare.com" and adr="/Juergen/index.htm"trying the same with host="Espruino.com" and adr="/modules/servo.js" returns a 404 from mini.morphyre.com
using host="http://www.Espruino.com" and adr="/modules/servo.js" gives a totally strange feedback, echo of command is this: "Host:http://www.Espruino.comrvo.js"which is very strange in my eyes
testing with a subdomain from my server it works fine
host="JUMFlot.JUMWare.com" adr="/"hope this helps a little bit for your testing.
Promises are a powerful tool to avoid callback-hell.
For Espruino I was searching for a tiny solution and found 7 Lines from Krasimir.
Based on this I wrote a simple flow solution.
It supports
Handling is simple as you can see here: