Post your best Lua script examples here

User avatar
By fixingthingsguy
#12757 Dear Stefan: Thanks for providing this module. I also saw this on the Parallax forum.
So I have a set up with an Arduino Nano and I want to send serial data to the ESP8266 under NodeMcu using LUA.
So I first loaded your script, called it "serial" on the Esp8266/Nodemcu.
Then I wrote a simple sketch in Arduino to print("cmd_2(78)" ) to see if I receive it on the ESP8266.
I receive it correctly. But it is not being processed on the ESP8266. ie it shows cmd_(78) but not the serial.lua processing which should show print("cmd_2(78)received"). I'm obviously doing something wrong.
The connection from the esp28566 is tx-rx(ard),rx-tx(ard) and ard-d8->ttlinterface* tx and ard-d9->ttlinterface rx.
Any suggestions to debug ?
Thanks
Regards

PS: I have successfully tested the esp8266 standalone with nodemcu and it transmits to my webserver flawlessly, periodically as required.


*ttlinterface(CP2102):http[url]://www.ebay.com/itm/321546809495?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
User avatar
By StefanL38
#12763 Hi FixThingsGuy,

how did you check that the ESP8266 receives the string "cmd_2(78)"?
The only way that my code-example can check it is sending back "cmd_2(78) received"

Did you test the script with LuaLoader.exe?

assuming your scriptfile is named "serial.lua"
Did you start the script through sending the command 'dofile("serial.lua")' ?

If you haven't started the script through the dofile-command nothing will happen.

You can start the script serial.lua inside LuaLoader.exe
In two steps:

1. upload file serial.lua to ESP8266 through button Upload File...
2. after uploading a file in he dropbox above button dofile the name of the file that was uploaded last is preselected. Then click the button dofile

best regards

Stefan
User avatar
By fixingthingsguy
#12764
StefanL38 wrote:Hi FixThingsGuy,

how did you check that the ESP8266 receives the string "cmd_2(78)"?
The only way that my code-example can check it is sending back "cmd_2(78) received"
>>>That's revealing. I think therein lies the problem. I must be seeing output from the Arduino serial port rather than the ESP8266.
After I compile the Ard. sketch I get choice of 2 ports (com3 and com4-using Alt.Serial). I turn up com4 (only for the Lua.Loader) and that's where the Alt.Serial output (similar to soft.serial) shows up with the example above. I did run the do-file repeatedly.
I'll draw a picture and send along, must be something I'm doing incorrectly....


Did you test the script with LuaLoader.exe?
>>Yes, it works perfectly.

assuming your scriptfile is named "serial.lua"
Did you start the script through sending the command 'dofile("serial.lua")' ?
>>Yes did that too.

If you haven't started the script through the dofile-command nothing will happen.
>>Got that.


You can start the script serial.lua inside LuaLoader.exe
In two steps:

1. upload file serial.lua to ESP8266 through button Upload File...
2. after uploading a file in he dropbox above button dofile the name of the file that was uploaded last is preselected. Then click the button dofile
>>I believe I;m doing this right. I think my connections are wrong, I have to check and get back
with a picture.
best regards

Stefan


>>Thank you very much for your prompt response. I have to take a break now and get back at this later.
Regards
User avatar
By fixingthingsguy
#12765 Here's the error I'm receiving on the Lua loader
cmd_2(78)
stdin:1: attempt to call global 'cmd_2' (a nil value)


The Ard sketch says
Serial.println("cmd_2(78)");
altSerial.println("cmd_2(78)");

If the Ard is disconnected and I enter manually
>cmd_2(78)
I get the 'received' response.

Thanks for your time
Regards