-->
Page 1 of 1

How to use file.write as a substitute for io.write?

PostPosted: Thu Aug 16, 2018 6:08 pm
by timg11
Deep in the NodeMCU Developer FAQ there is brief mention:
"For example, the standard io and os libraries don't work, but have been largely replaced by the NodeMCU node and file libraries."

But nowhere is it explained how to use file.write as an alternative for io.write.

A simple replacement of file.write for io.write yields:

Code: Select allPANIC: unprotected error in call to Lua API (calculateTime.lua:30: open a file first)


What file is to be opened to get the same serial console that is used by print()?
Where is this documented?

Re: How to use file.write as a substitute for io.write?

PostPosted: Fri Aug 17, 2018 12:03 am
by marcelstoer
Kudos for reading the FAQ.

I suggest you first consult the respective module documentation, https://nodemcu.readthedocs.io/en/lates ... ules/file/ in this case, before you just blindly execute functions.

I'm not sure I understand your other question(s) but it's explained here https://nodemcu.readthedocs.io/en/lates ... ules/uart/

Re: How to use file.write as a substitute for io.write?

PostPosted: Fri Aug 17, 2018 11:59 am
by timg11
Regular (non-NodeMCU) Lua offers io.write as a mechanism to provide more "direct" output to STDOUT than Print.

But, io doesn't exist in NodeMCU.

I want to use file.write, but need to know what file to open to emulate the behavior of Print and io.write in non-NodeMCU Lua.

Is STDOUT a file? I don't find it in the [url=https://nodemcu.readthedocs.io/en/latest/en/modules/file/
]NodeMCU docs[/url] for file.

I've searched elsewhere, and have not been successful in finding the NodeMCU equivalent to the STDOUT file.

Re: How to use file.write as a substitute for io.write?

PostPosted: Fri Aug 17, 2018 3:30 pm
by timg11
The correct way to write to the same device as Print is to use uart.write(0,<string>)