attempt to index a nil value (field 'eth0')

236 views Asked by At

this is a Lua quickapp problem i install it a year ago and it was working fine but went through some problems in my system because of electricity. This is the part I Have problem with:

function BroadlinkDeviceManager:discover(func)
local blDevices = {}
local network = api.get("/proxy?url=http://localhost:11112/api/settings/network")
local myIP = network.networkConfig.eth0.ipConfig.ip
-- for debugging
if dofile then
    myIP = "192.168.1.59" -- Util.getIPaddress() --
end

The Quick app is for Broadlink RM4 when I setup it again to my wifi the QA always give me this error

[DEBUG] [QUICKAPP1613]: ./include/manager.lua:97: attempt to index a nil value (field 'eth0')
[ERROR] [QUICKAPP1613]: QuickApp crashed
[ERROR] [QUICKAPP1613]: Unknown error occurred: handleJsonRpc

I search it but i can't find any solution I also asked in forum but I got nothing. If there is any one can help me with this.

2

There are 2 answers

0
lcheylus On

You must verify if network.networkConfig.eth0 is not nil before indexing network.networkConfig.eth0.ipConfig.ip :

local myIP
if network.networkConfig.eth0 ~= nil then
  myIP = network.networkConfig.eth0.ipConfig.ip
end
0
Abdullah On

Thank you for your response, the error disappear put there was a function to check the IP of the device

local function makeDiscoverDevicesMsg() 
local ipa1, ipa2,ipa3, ipa4 = myIP:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)")

then I edit to be "^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$"

I also try to make every variable with (tonumber) but all give me the same error attempt to index a nil value (upvalue 'myIP')