2017-09-22 4 views
-1

저는 ESP8266에 새로 입문했습니다. 루아 코드에 WebSockets을 추가하려고 시도하지만, 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() 
+1

NodeMCU 펌웨어 빌드를 어떻게 구성 했습니까? (https://nodemcu-build.com/) 스크립트의 첫 줄에'websocket = require ("websocket")'을 넣으려고 했습니까? –

답변

0

위의 코드에 3 가지 문제점이 있습니다.

주된 문제는 펌웨어에 websocket 모듈이 누락 된 것 같습니다. 수동으로 빌드하는 경우 https://github.com/nodemcu/nodemcu-firmware/blob/master/app/include/user_modules.h#L75의 주석을 삭제하십시오.

또한 이벤트 처리기를 등록해야 각 이벤트가 해고 될 수 있습니다. 나는 너를 만날거야 정확하게 할. 그러나 기본적으로 wifi.sta.configauto connect=true을 사용합니다.이 경우 이벤트 모니터가 시작되기 전에 WiFi 등록 프로세스가 시작됩니다.

마지막으로 wifi.sta.config의 서명이 몇 달 전에 변경되었습니다 (자세한 내용은 문서 참조). 이제 wifi.sta.config{"SSID","PWD"}라고 말해야 Lua 테이블을 전달할 수 있습니다.

+0

재부팅 후 메시지를 볼 때 websocket 모듈이 빠진 것은 틀림 없습니다. 그런 다음 웹 소켓으로 다른 빌드를 만들었습니다. 고마워요 @ 마르셀 – maheshgupta024

관련 문제