Skip to content

[Question]use of readData() on lua interpreter #1092

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

Open
kleffa opened this issue May 5, 2025 · 3 comments
Open

[Question]use of readData() on lua interpreter #1092

kleffa opened this issue May 5, 2025 · 3 comments
Labels

Comments

@kleffa
Copy link

kleffa commented May 5, 2025

local pin = readData([ESP201] P=4)
if pin == 1 then
print("[ESP201] P=4 V=0 ")
else
print("[ESP201] P=4 V=1 ")
end

I'm writing a couple of scripts like this one (just change state of flash on esp32cam). I know this can be just a digitalRead, but its about using readData() , this doesnt work, I missed something?
can readData used to read serial, like M27 data?

any help please to clarify it

@kleffa kleffa added the question label May 5, 2025
@luc-github
Copy link
Owner

readData() read any string received by lua interpreter, from ESP3D if you send any [ESPXXX] command but also any string from serial or usb
use available() to check if any string is available then readData() to collect one string at once

here a sample script that echo any message received by lua interpreter

--[[
    Echo Serial

    This example echo serial outout to serial with echo: header 
    Put this script in the ESP3D flash file system and call it from the init script in 
    configuration.h.
    #define ESP_AUTOSTART_SCRIPT "[ESP300]/FS/detectpush.lua"

    Be sure to have the following line comment out in the configure.h:
    #define ESP_LUA_INTERPRETER_FEATURE
    ]]--

-- Setup
local availableMsg = 0
local message = ""
while (true) do
    -- check if have data
    availableMsg = available()
    -- if any message
    if (availableMsg > 0) then
        message = "echo:" .. readData()
        print(message)
    end
    -- yield to other tasks
    yield()
end

I know documentation https://esp3d.io/ESP3D/Version_3.X/documentation/lua/ is very light but no one seems used this feature until now because I got no feedback on this feature, so feel free to propose, submit better documentation, of course I will help by answering any question or give clarifications if necessary

@luc-github
Copy link
Owner

@kleffa did this answered your question ?

@kleffa
Copy link
Author

kleffa commented May 6, 2025 via email

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

No branches or pull requests

2 participants