私はESP8266にとってかなり新しいです。 WebSocketをLuaコードに追加しようとしていますが、毎回documentationを参照してWebSocketを使用しようとすると、グローバルwebsocket
(nil
値)のインデックスを作成しようとすると、デバイスがエラーをスローします。私は本当に何かがある場合は、私はこれで私を助けてもらえますか?グローバル 'websocket'のインデックスを作成しようとしています
function connectToSocket()
print ("Connect to socket called, OK.")
local ws_client = websocket.createClient()
end
wifi.setphymode(wifi.PHYMODE_N)
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
wifi.sta.eventMonReg(wifi.STA_IDLE, function() print("IDLE") end)
wifi.sta.eventMonReg(wifi.STA_CONNECTING, function() print("CONNECTING...") end)
wifi.sta.eventMonReg(wifi.STA_WRONGPWD, function() print("WRONG PASSWORD!!!") end)
wifi.sta.eventMonReg(wifi.STA_APNOTFOUND, function() print("NO SUCH SSID FOUND") end)
wifi.sta.eventMonReg(wifi.STA_FAIL, function() print("FAILED TO CONNECT") end)
wifi.sta.eventMonReg(wifi.STA_GOTIP, function()
print("GOT IP "..wifi.sta.getip())
connectToSocket()
end)
wifi.sta.eventMonStart()
wifi.sta.connect()
NodeMCUファームウェアのビルドはどのように設定しましたか? (https://nodemcu-build.com/) 'websocket = require(" websocket ")'をスクリプトの最初の行に入れようとしましたか? –