Errors with Lua examples.

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kingfishernw
 
Posts: 16
Joined: Fri May 11, 2018 6:58 pm

Errors with Lua examples.

Post by kingfishernw »

Hello...

Okay... my brand new Feather ESP8266 Huzzah seems to be working. :)

For now, I am testing with the pre-installed Lua, although I do intend to reflash for Arduino once I finish with these tests. Using TeraTerm (couldn't get Putty to send characters), and working from your Lua examples for the Feather ESP8266 Huzzuh underneath your "HELLO WORLD" headline, I have successfully performed both the manual and then the subsequent simple loop test for blinking the red led. I then moved on to the next two examples, both of which gave me syntax errors while typing them in. (I am pasting in the lines of code one by one because pasting in the whole mini-program all at once sends the characters to the ESP8266 too fast. I'm sure that the Arduino IDE will take care of this for me.)

First, with the example that follows your text "a smarter way to blink an LED is to use the timer capability to set off the LED control," I am able to type in the definition of the three local variables without trouble. However, I run into trouble as soon as I reference them. For example, the Lua interpreter gives me the message "stdin:1: bad argument #1 to 'mode' (number expected, got nil)" after I typed in "gpio.mode(pin, gpio.OUTPUT)" which is the first line of code that references one of the local variables. (If I replace the "pin" with the value 3, I don't get an error, but the subsequent loop simply MUST be able to reference the variables.)

Moving on, I reset the ESP8266 board and continued on to the first wifi scanning Lua example. The "wifi.setmode(wifi.STATION)" line of code was accepted, as were the first three lines of:

Code: Select all

function listap(t)
      for k,v in pairs(t) do
        print(k.." : "..v)
      end
end
wifi.sta.getap(listap)

However, as soon as I typed that first "end" I received the message

stdin:3: unfinished string near '"..v)'

Of course, I already admitted that it is not my intention to become a Lua developer. However, I had considered it best practice to ensure that your basic functional examples work before I reflash the part. Accordingly, any guidance you can offer is greatly appreciated. (Btw, the Lua website is not nearly as nicely put together as your own.)

Thank you so much!

P.S. I am typing in the lines of code one by one because pasting in the whole mini-program all at once sends the characters to the ESP8266 too fast. I'm sure that the Arduino IDE will take care of this for me.
Last edited by adafruit_support_mike on Sat Jul 07, 2018 2:42 am, edited 1 time in total.
Reason: added CODE tags

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Errors with Lua examples.

Post by adafruit_support_mike »

Try entering the for() loop like this:

Code: Select all

      for k,v in pairs(t) do print(k.." : "..v) end
Strictly speaking, the "unfinished string" error just means the Lua interpreter didn't the 'end' when you entered the print() statement. If NodeMCU treats each line as a statement to execute, it would see that as a problem.

User avatar
kingfishernw
 
Posts: 16
Joined: Fri May 11, 2018 6:58 pm

Re: Errors with Lua examples.

Post by kingfishernw »

Thanks so much for answering so quickly, Mike.

Yes sir... your all-on-one-line version did work flawlessly. That is

for k,v in pairs(t) do print(k.." : "..v) end

instead of on three separate lines with indentation. That said, please appreciate that, as a C programmer, the Lua formatting in your website example seemed perfectly natural to me. Although new to Lua and ESP8266, I am an experienced coder and EE. I well know how to bootstrap myself onto a new platform and, certainly, starting with your ultra-basic Lua examples (verbatim) seemed a reasonable approach to testing my new ESP8266 Feather. Is the example simply wrong? If so, is this the kind of thing one should expect Adafruit to (eventually) fix?

Thank you again!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Errors with Lua examples.

Post by adafruit_support_mike »

Carl Sagan once said, "if you want to make an apple pie from scratch, you first have to create the universe."

Any example or tutorial has to make assumptions about what the reader already understands, and the information they're likely to need. Any such decision will have gaps that catch someone. We have to keep the text fairly sparse though, or people start missing important details in the wall of "what you need to know before you start doing the interesting parts".

We use these forums to handle the cases where someone gets caught. If we see a trend of people getting caught by the same issue, we take that as a cue to edit the tutorial and add some more background. Single instances though.. no. That's the path of abdicating decisions to whoever complains. That can only be a rational choice if everyone making a complaint invests the effort to remain logically self-consistent with all the other complaints.

User avatar
kingfishernw
 
Posts: 16
Joined: Fri May 11, 2018 6:58 pm

Re: Errors with Lua examples.

Post by kingfishernw »

Mike, sir... you are both a very helpful and intelligent man.

When I did my original research and settled on the ESP8266, I soon settled on Adafruit as well because your website was full of tons of helpful information and examples, none of it hampered by ridiculous typos and obvious translation problems. (The competitors I found either had badly-written, badly translated and/or very sparse sites.) Clearly, Adafruit was a "real" company. Then, I asked a number of presales questions on your forum and you and/or "Bill" helped me three times -- twice within 24 hours and once within 48. So... I'm a fan, both of you and Adafruit. (I've already recommended Adafruit to a number of people.)

I appreciate and understand your answer below. While I don't have a problem with it, I simply can't help keep myself from emphasizing that the code that tripped me up is part of a beginner's tutorial and, as formatted, it is simply invalid. (I respect your statement that it isn't bothering anybody else, perhaps because they are using Arduino, just as I will be.)

I still like you and your company very much and you need not respond to this -- I'm good with Adafruit.

Thank you again, and have a great rest of the day!

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”