Description
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