-
The problem with this approach is that the data is a 30kB hex file, its not something I can easily type into the console on the Web IDE. However I think I may have found a solution, by uploading this data with the firmware hex file I could write it to the Espruino's flash directly.
I can then use the nRF toolbox app to write this modified firmware to the nRF chip.
-
I would like to be able to send files over bluetooth to the RAK8211 board. This board uses the nRF52, so it should be possible to send data over bluetooth to it.
I cant seem to see anything out of the box that would allow for bluetooth file transfer.
I noticed that Espruino's filesystem library works with SD cards, and one of the arguments is a source path.Would it be possible to use a bluetooth address as the source path instead of the SD card directory?
I realise this may require 'hacking' espruino codebase to be able to do what I need to do.Alternatively there is the nRF connect app which is used to access the device and upload firmware to it. We are currently using the nRF toolbox to flash the firmware to the device. I suspect there could be some way to upload files using the same interface.
Do you have any ideas how I could do this?
-
I'm currently using the "JS & CSS Minifier" extension on VSCode. It works excellently, minimizes to ES6 and I've had no issues so far.
https://github.com/olback/es6-css-minifyThanks for clarifying how the modules as functions behaves, that makes sense to me now.
-
I just tested it with minification off and that seems to be correct. with all minification off it works. (with or without modules as functions enabled).
I would rather not share the code I'm uploading, aside from being over 2000 lines, it will be used for a proof of concept and includes some proprietary information that I'd have to remove before uploading. Sorry. I know its easier to help when you have the full code.
As for the minification settings: Its working fine using "Simple Optimizations", as long as "modules as functions" is not checked.
If it is checked then I need to use "No minification".
Using "Simple optimizations" or "Whitespace Only" results in the $jscomp error above.But I'm not using the functionality from "modules as functions", so it can remain unchecked for my project.
So it seems that $jscomp is inserted when transpiling ES6 -> ES5.
That makes sense because I am using ES6 code, making use of the arrow notation which seems to be transpiled to ES5 in the Closure Compiler.Just as an experiment, I have used an ES6 aware minifier, which doesn't transpile the arrow notations. This has worked and has produced code smaller than the closure compiler minifier. (4900 vs 4600 bytes).
-
I figured out the issue.
Modules as functions cant be ticked. If its unticked it works fine, if it doesnt, then it comes up with an error regarding $jscomp.initSymbol or $jscomp.makeIterator.If I use closure compiler to minify my code, these variables are not part of the code, which confused me, but when I did a dump() I could see that these variables were in the code that was uploaded, and were causing problems. Since unchecking the modules as functions box its stopped producing the error and allows my code to execute.
According to the webIDE this function is still in BETA, so I'm not sure if this feedback will be useful in order to fix it for upcoming releases.
-
The same thing:
Uncaught ReferenceError: "$jscomp" is not defined at line 1 col 150 ...(var $jscomp$iter$0=$jscomp.makeIterator(data),$jscomp$key$x... ^ in function called from system
But when I use it as code inside the build - as in I've rebuilt the .hex firmware file including the module in source code, it works.
-
I am actually using the name without the file extension, sorry about writing it wrong in my post. [edited now]
Even if that was the problem, it would give me an error saying it failed to load it. This loads it but then crashes on execution.I also run it without minification until I'm done w/development. I was developing this particular module months ago in the sandbox, and thought I was done and minified it and added it to the build. (the file in question is a board file, specifying the lower level AT commands of a custom board).
However, I need to update the file, so I am going back to tweak it, but the sandbox version no longer works because of some error. Even without the minification, I'm still getting an error which looks similar to what closure compiler would give. (I've noticed $jscomp is a variable in the closure compiler, so I shouldn't expect to see this if my code isn't minified.)
-
Not sure if you can help, but I get an error running a custom js module from the sandbox/modules folder and I've been scratching my head for hours working out why. Particularly when it worked using a previous version of Espruino.
I'm using a
require('testingModule')
command to load the testingModule.js file and it loads fine, however when it executes a function in that module I get the following error:
With module minification on:
Uncaught Error: Function "initSymbol" not found! at line 1 col 3
m.initSymbol();m.initSymbol();m.initSymbolIterator();m.initS...
in function "makeIterator" called from line 1 col 105 ...var
d="",k=m.makeIterator(e),f=k.next();!f.done;f=k.next())d...With module minification off:
Uncaught ReferenceError: "$jscomp" is not defined at line 1 col 150
...(var $jscomp$iter$0=$jscomp.makeIterator(data),$jscomp$key$x...
in function called from systemThe function uses an AT command to connect the module to the server using TCP.
I know there are no issues with the function, because when I include it in the build (/libs/js), it works and executes that function without any errors.
What is really odd is that there is no "initSymbol", "makeIterator" or "$jscomp" inside my code at all. Not in this module or any other application code that I've written.
This same sandbox functionality was working when I was using an older version of Espruino.
-
Hi Gordon,
We made our own QuectelBC95.js file, because our device uses a BC95-G module.The low level code that we've written in this file is what is causing issues, specifically in the receive handler. So its nothing with Espruino that is the issue. I have figured out a solution now, by using the "+NSONMI" receive handler to output the number of bytes received and then retrieve them at a later time using "AT+NSORF", rather than retrieve them in the receive handler itself.
Thanks for your help.
-
-
I forgot to mention that I had tried that one too.
Unfortunately I got the same result:function getHttp(options, callback) { http.get(options, function(res) { print("available: " + res.available()); //returns 168 print("Content-Length: " + res.headers['Content-Length']); //returns 300 var content = ""; res.on('data', (data) => content+=data); res.on('close', (data) => print("close: " + content)) res.on('error', (e) => print("Error: " + e)); }).on('error', function(e) { print("ERROR", e); }); }
Results:
available: 168
Content-Length : 300
close: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":tI only added the "manual read" after it failed the first time, just to see if I could force it to read all 300 characters, which didnt work either because theres only 168 bytes available.
-
Using http.get():
http.get(options, function(res) { print("available: " + res.available()); //returns 168 print("Content-Length: " + res.headers['Content-Length']); //returns 300 print("Manual read: " + res.read()) res.on('data', function(data) { print("\t Response: code: " + res.statusCode); print("--> " + data); }); res.on('close', (data) => print("close: " + data)); //for debugging res.on('drain', (data) => print("drain: " + data)); //for debugging res.on('error', (e) => print("Error: " + e)); //for debugging }); req.on('error', function(e) { print("ERROR", e); });
Results:
available: 168
Content-Length: 300
Manual Read: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
code: 200
--> [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":tUsing http.request:
var req = http.request(options, function(res) { print("available: " + res.available()); //returns 168 print("Content-Length: " + res.headers['Content-Length']); //returns 300 print("read: " + res.read()) res.on('data', function(data) { print("\t Response: " + "code: " + res.statusCode); print("--> " + data); }); }); req.on('error', function(e) { print("error: " + e); });
Results:
available: 168
Content-Length: 300
Manual Read: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
code: 200
--> [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":tI also tried concatenating a string with each data that is returned:
tempMsg = ""; var req = http.request(options, function(res) { var l = res.headers['Content-Length']; print("l = " + l); res.on('data', function(data) { tempMsg += data; if (tempMsg.length >=1) { print("tempMsg: " + tempMsg); print("End of Message"); } }); res.on('close', function(data) { print("\t Response: " + "code: " + res.statusCode); }); res.on('error', (e)=> print("error: " + e)); //for debugging }); req.on('error', function(e) { if (callback) callback(e.code, e.message); }); req.end(body);
Results:
l = 300
[{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
tempMsg: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
End of Message
code: 200 -
I am working on a RAK8211 module with Espruino 2v01.17
I have been able to successfully send data using the http module with a "POST" request.
I am now trying to receive data from a server. To do this I am sending this HTTP request:GET /api/v1/devices/configuration HTTP/1.1
User-Agent: Espruino 2v01.17
Content-Type: application/json
Host: serverPath.comThis is the data I am expecting, and the data that I am actually receiving:
Expected:
[{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":true,"pressure":true,"temperature":true,"eventTriggers":true},{"type":"Actions","reboot":false,"dfwUpdate":false,"findDevice":false}]
Received:
[{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
As you can see, the response is truncated.
I have tried this using both the http.get function and using the http.request function, both results in the same output.
What is interesting is that the content length is 300, but only 168 characters are printed.
When I do a print(res.available()) it returns 168The response from the server has the following headers:
HTTP/1.1 200 Server: nginx/1.12.2 Date: Tue, 12 Feb 2019 06:28:31 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 300 Connection: close X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY
Why would the available bytes be showing only 168 when the Content-Length is 300 bytes?
Some more detailed information of things I've tried below: -
I was going through the Espruino Source code and noticed that the sleep uses WFE instead of WFI for the nrf52
It was my understanding that WFI is typically used for standby and WFE is used for spinlocks. Just wondering what the benefit of using WFE is in this instance, and if we can get more power savings by using WFI if we are sleeping for a long period of time with an Interrupt wake-up source?
-
I put together this implementation using a byte array without having to copy and allocate new strings.
var buff = new Uint8Array(1024); //ascii string to byte array for (let i = 0; i < data.length; i++) { let c = ('0' + data.charCodeAt(i).toString(16)).slice(-2); buff[i * 2] = c.charCodeAt(0); buff[i * 2 + 1] = c.charCodeAt(1); } //Ascii string from byte Array - Note 'apply' only works for 64 arguments function fromByteArray(len) { if (len < 64) return String.fromCharCode.apply(String, buff.slice(0,len)); for (var result = [], i = 0; i < len; i += 64) { result.push(String.fromCharCode.apply(String, buff.slice(i, i + 64))); } return result.join("").slice(0,len); } //Hex string to byte array function toByteArray(data) { for (let i = 0; i < data.length/2; i++) { buff[i] = parseInt((data.substring(i*2,i*2+2)),16) } buff.slice(0,data.length /2); }
After running a process.memory() command before and after these changes, I can't see any significant memory savings. Should we expect any improvements in memory usage by using a byte array, or does the string append provide the best use of memory allocation?
What improvements could we make to this implementation to improve memory allocation?
Thanks.
I actually did this today, using bin2c.exe to convert the binary data to a .h file which I included in Espruino/targets/nrf5x, then using a jsWrapper to return the address of that array from the .h file.
It seems to work pretty well. Now I can create a loop in my javascript to retrieve that data and I can re-flash that data using the nRF toolbox app in DFU mode.