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