Je suis assez nouveau sur l'ESP8266. J'essaye d'ajouter les WebSockets au code de Lua, mais chaque fois que j'essaye d'employer le WebSocket regardant le documentation, le dispositif jette l'erreur comme tentative d'indexer global websocket
(une valeur de nil
). Je ne suis pas vraiment sûr s'il y a quelque chose à importer, quelqu'un peut-il m'aider s'il vous plaît avec ceci.Tenter d'indexer le 'websocket' global
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()
Comment avez-vous configuré votre build de firmware NodeMCU? (https://nodemcu-build.com/) Avez-vous essayé de mettre 'websocket = require (" websocket ")' comme première ligne du script? –