2016-07-17 86 views
0

我用Lua腳本編寫了一個ESP8266 NodeMCU。正如我在調試剛剛在開始時切斷字符串並進一步延伸的問題。我從ESP8266發送到Android手機。ESP8266字符串最大大小247字節?

我在通過UART接口測試esp時遇到了以下問題: 當我聲明字符串容器時,最大字符串大小爲247個字符。之後,我超過247有一個錯誤:

stdin:1: unexpected symbol near '='

絃樂顯然是過於漫長,但我需要爲每串發送至少2048字節的最大效率。是否可以擴展字符串變量的輸入限制?

(我構建了一個2048字節的數據包和86字節開銷,用於HTTP獲取響應) ESP8266的TCP發送緩衝區爲2920字節。

str_resp0 = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n"; 
str_resp1 = "Connection: close\r\n\r\n"; 

send_buf = ""; 

uart.on("data", "$", 
    function(data) 
    t = {send_buf,data} 
    send_buf = table.concat(t); 

    if data=="quit$" then 
     uart.on("data") -- quit the function 
    end 
end, 0) 

srv=net.createServer(net.TCP) 
srv:listen(80,function(conn) 
    conn:on("receive",function(conn,payload) 
    --print(payload) 
    conn:send(str_resp0) 
    conn:send(str_resp1) 
    conn:send(send_buf) 
    send_buf = ""; 
    end) 
    conn:on("sent",function(conn) conn:close() 
    end) 
end) 
+0

你在說什麼Lua字符串? – greenapps

+0

'開始切斷並延長'?不明白。請舉個例子。 – greenapps

+0

我發--- ---緩衝=「懶惰的狐狸跳過一個燃燒的桶」在傳輸--->緩衝=「跳過一個燃燒的桶」。所以弦的開始就會丟失。 – ionman

回答

1

stdin:1: unexpected symbol near '='

聽起來很像你的 「IDE」 問題(ESPlorer?)。

此外,你應該批量發送長有效載荷。 SDK將數據包大小限制在大約1500字節,即standard Ethernet MTU

http://nodemcu.readthedocs.io/en/latest/en/modules/net/#netsocketsend有一些解釋和一個很好的例子。一些在ESPlorer試驗

srv = net.createServer(net.TCP) 
srv:listen(80, function(conn) 
    conn:on("receive", function(sck, req) 
    local response = {} 

    -- if you're sending back HTML over HTTP you'll want something like this instead 
    -- local response = {"HTTP/1.0 200 OK\r\nServer: NodeMCU on ESP8266\r\nContent-Type: text/html\r\n\r\n"} 

    response[#response + 1] = "lots of data" 
    response[#response + 1] = "even more data" 
    response[#response + 1] = "e.g. content read from a file" 

    -- sends and removes the first element from the 'response' table 
    local function send(sk) 
     if #response > 0 
     then sk:send(table.remove(response, 1)) 
     else 
     sk:close() 
     response = nil 
     end 
    end 

    -- triggers the send() function again once the first chunk of data was sent 
    sck:on("sent", send) 

    send(sck) 
    end) 
end) 

更新2016年7月18日

結果。本次測試使用的單一初始化的變量:

buffer = "A very long string with more than 250 chars..." 
  • 擊中「發送到ESP」(送炭的炭在UART)將失敗,一個類似於此報告錯誤。
  • 保存到一個文件工作正常。
    • 點擊「保存」,會將該行保存到文件系統中的文件,例如paul.lua
    • 點擊'保存到ESP',將發送paul.lua到設備。
    • 如果它不是作爲「保存到ESP」的一部分自動完成的,則可以將dofile("paul.lua")發送到設備。這將使變量buffer在全局空間中可用。
    • 發送會將整個字符串打印到終端窗口。
+0

我使用盧阿裝載機。 「Puzzle Pukes this though:stdin:2:未完成的字符串靠近''''' ,所以問題仍然存在。似乎有侷限性或者我只是做錯了事情(一般情況下) – ionman

+0

示例函數雖然可行,謝謝! – ionman

+1

好吧,正如我所說的,通過UART傳輸這麼長的字符串到設備是一個問題,一旦分配給一個變量的字符串增長到超過250個字符,我可以用ESPlorer重現這個問題,試着將字符串保存到一個單獨的'.lua'文件中, _save_(而不是傳輸char-by-char)文件到設備,然後加載文件。 –

0

這個問題似乎是不可避免的。參考espressif論壇:

「由下級代碼添加的延遲是20ms它被記錄!」

所以事件框架不能被處理得比這更快。調整這一點的唯一方法可能是緩存微控制器中的數據並每20ms發送一次,或者安裝所謂的「ESP8266 FreeRTOS SDK」,其傳輸速度僅受uart速度限制。