Current Lua downloadable firmware will be posted here

User avatar
By gerardwr
#2714 I still have some questions on the API that are not clear to me reading the excellent documentation.

1. the node.key() function. This seems to be a way to act upon closing a switch connected to a GPIO. Is that a correct assumption? What’s the GPIO# where the switch should be connected.
2. the node.led() function. This seems to be a way to switch a LED connected connected to a GPIO. Is that a correct assumption. What’s the GPIO# where the LED should be connected.
3. Getting input from the in Lua is normally done with io.read(), but that’s not part if this implementation. What’s the way getting input into a variable?
User avatar
By zeroday
#2715
cendev wrote:
gerardwr wrote:
cendev wrote:you are welcome :) glad to hear that :) if only you were using windows or linux i would send the gui supported tcp project =) i'll upload them tomorrow, hope they'll help =)


Hi,

I have your python script to upload a lua file to the ESP running now on my Mac. I had to make a small change to remove the \n formatting character from the line variable (by using line.strip) . The original version resulted in an unwanted line break BEFORE to ]]) ending of the line This is probably due to a different line-ending character in Mac OS X. This is the changed version that runs OK on my Mac.
Code: Select all#!/usr/bin/env python

import socket
import time
import sys

toCreate = str(sys.argv[1])
toUpload = str(sys.argv[2])
ip = str(sys.argv[3])
port = str(sys.argv[4])

TCP_IP = ip
TCP_PORT = int(port)
BUFFER_SIZE = 1024

time.sleep(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send("file.open(\"%s\",\"w+\")" %(toCreate,))
time.sleep(0.1)
with open(toUpload) as f:
    for line in f:
#        print(line)
        print line.strip('\n')
        s.send("file.writeline([[%s]])" % line.strip('\n'))
        time.sleep(0.1)
s.send("file.close()")
s.close()


Uploading a stupid textile with 4 "hello world" lines in it looks like this on the ESP:
Code: Select all> dofile("file.lua")
> file.open("test1.lua","w+")
file.writeline([[print("hello world")]])
file.writeline([[print("hello world 2")]])
file.writeline([[print("hello world 3")]])
file.writeline([[print("hello world 4")]])
file.close()
c_G.RS.fJ[.fJS.f.
lua: cannot open init.lua
NodeMcu 0.9.2  powered by Lua 5.1.4
> file.list()
  file.lua size:125
  test1.lua size:90
> dofile("test1.lua")
hello world
hello world 2
hello world 3
hello world 4
>

When the upload is finished the ESP reboots, probably due to the Python script closing the connection.

Thanks to your script I have an operational upload mechanism now running on my Mac. Time for some Lua coding now ;)


great news :) btw if file.flush is the same as the python flush, it can be a good idea to file.flush after sending lines. :) so data will no longer be buffered and the ram/buffer overflow can be avoided :) i'm not so sure but i think it can be usefull.

as there is no io library and i'm kinda confused with usage of file.seek method i'm kinda having hard times to find the eof :/ if only i can find the end of the file my windows tool will be ready and kivi python will be almost done too :)

found it.. :) in the loop, if file.seek(cur) is same for twice its end of file :) now to write the readfile script


hi,
file.readline() supposed to return nil if it hits EOF.
but there is a bug here, since file.readline() does not include the EOL(end of line: "\n"),
so it also returns nil when a line is only contain one char "\n".
I will fix this, file.readline() returns will include "EOL". then if it returns nil, means EOF.
User avatar
By zeroday
#2716
gerardwr wrote:I still have some questions on the API that are not clear to me reading the excellent documentation.

1. the node.key() function. This seems to be a way to act upon closing a switch connected to a GPIO. Is that a correct assumption? What’s the GPIO# where the switch should be connected.
2. the node.led() function. This seems to be a way to switch a LED connected connected to a GPIO. Is that a correct assumption. What’s the GPIO# where the LED should be connected.
3. Getting input from the in Lua is normally done with io.read(), but that’s not part if this implementation. What’s the way getting input into a variable?


1,2, node.key() node.led() is two api for GPIO16. in the development kit GPIO16 connect to one LED, and one BUTTON.
node.key("long", function() end ) register a call back function to LONG press(>4 or 5 seconds) of the BUTTON.
node.key("short", function() end ) register a call back function to SHORT press of the BUTTON.
node.led(400,500) means get the LED switch 400ms low and 500ms high.
some ESP module connect GPIO16 to chip RESET pin, and can't used as KEY or LED output.

3, there is no method to get user input from serial to a variable now. it go directly to lua interpreter, sorry for that.