Issue uploading Lua code to nodemcu on ESP32 due to missing file.open()

113 Views Asked by At

I'm trying to run nodemcu on an ESP32 (more memory than esp8266). I've build the firmware using the sources from https://github.com/nodemcu/nodemcu-firmware.git, the dev-esp32 branch. The build was done on a windows/WSL2/Ubuntu system.

The firmware works, however I am having issues with uploading and saving lua files. I've tried various tools, for example http://chilipeppr.com/esp32.

Functions like 'Heap' and 'Reset' work fine. However, uploading files fails. The console output is:

file.open("unnamed1.lua", "w")
 file.writeline([[print("Test")]])
 file.writeline([[]])
 file.close()
 node.compile("unnamed1.lua")
> file.open("unnamed1.lua", "w")
Lua error:  stdin:1: attempt to call field 'open' (a nil value)
stack traceback:
    stdin:1: in main chunk
    [C]: ?
    [C]: ?
> file.writeline([[print("Test")]])
Lua error:  stdin:1: attempt to call field 'writeline' (a nil value)
stack traceback:
    stdin:1: in main chunk
    [C]: ?
    [C]: ?
> file.writeline([[]])
Lua error:  stdin:1: attempt to call field 'writeline' (a nil value)
stack traceback:
    stdin:1: in main chunk
    [C]: ?
    [C]: ?
> file.close()
Lua error:  stdin:1: attempt to call field 'close' (a nil value)
stack traceback:
    stdin:1: in main chunk
    [C]: ?
    [C]: ?
> node.compile("unnamed1.lua")
Lua error:  stdin:1: cannot open unnamed1.lua: No such file or directory
stack traceback:
    [C]: in function 'compile'
    stdin:1: in main chunk
    [C]: ?
    [C]: ?

Apparently, ESP8266 nodemcu implements file.open() where ESP32 nodemcu doesn't (ESP32 seems to implement the Lua io lib instead).

Am I having a build issue? I don't think so as https://nodemcu.readthedocs.io/en/dev-esp32/modules/file/ doesn't list file.open()

Is there an issue with the upload tools failing to detect my ESP32? Upon reset, my firmware reports as: ''' NodeMCU ESP32 build unspecified powered by Lua 5.1.4 [5.1-doublefp] on IDF v4.4.3 '''

Any help is appreciated.

3

There are 3 best solutions below

0
ESkri On

Try io lib instead.

do
    local file = io.open("unnamed1.lua", "w")
    file:write[[
        print("Test")
    ]]
    file:close()
end
node.compile("unnamed1.lua")
0
Dave Bamford On

If you need to upload files to the ESP32 using the io-module use this branch of nodeMCU-Tools..serg3295 NodeMCU-Tool

It took me hours of searching to find this. Its a command line tool, so not as easy to use as Chillipeppr or ESPlorer.

0
serg3295 On

There is VS Code extension NodeMCU-Tools (marketplace.visualstudio.com). You can use it instead of ESPlorer.