Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload code to flash using node module #143

Open
RobertSmart opened this issue Oct 15, 2021 · 2 comments
Open

Upload code to flash using node module #143

RobertSmart opened this issue Oct 15, 2021 · 2 comments

Comments

@RobertSmart
Copy link

Hi, I'm trying to upload a file to the flash memory on an ESP32 so that I can stream it (I'm currently doing this using storage, but thought I would try and use the extra space in flash for something useful.)

I've run E.flashFatFS({ format: true }); so I know its set up to receive a file.

The file I'm trying to upload is a minififed html file.

using the cmd line and the --storage option I can upload this just fine to storage. However I'm trying to send this to the flashFile system using this code:

`var esp = require("espruino")
var fs = require ('fs')
var path = require('path')
let filename = 'site.html'
let fpath = './dist'

esp.init(function(e){
Espruino.Config.BAUD_RATE = "115200";
Espruino.Config.BLUETOOTH_LOW_ENERGY =false;

let fileContents = fs.readFileSync(path.join(fpath,filename))

let code = require('fs').writeFileSync('${filename}', '${fileContents}');

esp.sendCode("COM5", code, function(result) {
console.log('GOT RESULT')
console.log(result)
});
});`

The error I'm getting is

SyntaxError: Unexpected token (1:2261)
at Parser.pp$5.raise (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:3416:15)
at Parser.pp.unexpected (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:741:10)
at Parser.pp.expect (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:735:28)
at Parser.pp$4.parseExprList (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:3283:14)
at Parser.pp$4.parseSubscript (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:2645:27)
at Parser.pp$4.parseSubscripts (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:2602:26)
at Parser.pp$4.parseExprSubscripts (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:2586:23)
at Parser.pp$4.parseMaybeUnary (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:2549:19)
at Parser.pp$4.parseExprOps (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:2482:21)
at Parser.pp$4.parseMaybeConditional (D:\Code\Embedded\Sensor_Stick\node_modules\acorn\dist\acorn.js:2465:21) {
pos: 2261,
loc: Position { line: 1, column: 2261 },
raisedAt: 2268
}

So I'm assuming its something to do with the quoted strings in the file?

I can upload a simple text string using this technique, but not a whole file. How does the cmd line encode the file so as not to fall foul of this same issue?

Thanks,

Rob Smart

@RobertSmart
Copy link
Author

would converting to hex or something before hand solve the issue or will that cause other issues?

@GermanWarez
Copy link

From my experience with an ESP8266:

  1. Convert the source to hex, using small chunks that will fit into the memory of the ESP8266, and leave a lot of free memory available for the interpreter
  2. Write the decoded hex chunks to 'Storage'
  3. Hard reset the ESP8266
  4. Copy chunks that fit into memory from 'Storage' to 'fs'.

Tested with files up to 100KB, with html, javascript and images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants