Relay:get(<instance>) does not work always 0 [SOLVED]

I have this script to check whether any of the relays are enabled.

function update()
    gcs:send_text(0, "GPIO READ")  

    for i=0, 6 do
        if relay:get(i) == true or relay:get(i) > 0 then
            gcs:send_text(0, string.format("Relay %s works!", tostring(i)))
        end
        gcs:send_text(0, string.format("Relay %s: %s - %s", tostring(i), tostring(relay:get(i)), tostring(relay:enabled(i))))
    end
    return update, 5000
end

return update()

Even though i toggle the relays like this:
image

My lua script can’t detect it. I get the following output:
image

the two true statements indicate that the ports are enabled. but yet they are always 0. I also tried arming the thing but it didn’t make difference.

I’m using an orange cube.

You are comparing an integer return value against a boolean, and thus the result is always false.

The returned state should be 0 or 1.

From libraries/AP_Scripting/docs/docs.lua

-- desc
---@param instance integer
function relay:toggle(instance) end

-- desc
---@param instance integer
---@return boolean
function relay:enabled(instance) end

-- return state of a relay
---@param instance integer
---@return integer
function relay:get(instance) end

-- desc
---@param instance integer
function relay:off(instance) end

-- desc
---@param instance integer
function relay:on(instance) end

@Yuri_Rage

I’m also comparing it as an integer as well
if relay:get(i) == true or relay:get(i) > 0 then

, I’m also printing it.

gcs:send_text(0, string.format(“Relay %s: %s - %s”, tostring(i), tostring(relay:get(i)), tostring(relay:enabled(i))))

But I also went ahead and changed it into this:

function update()
    gcs:send_text(0, "GPIO READ")  

    for i=0, 6 do
        if relay:get(i) == 1 then
            gcs:send_text(0, string.format("Relay %s works!", tostring(i)))
        end
        gcs:send_text(0, string.format("Relay %s: %s - %s", tostring(i), tostring(relay:get(i)), tostring(relay:enabled(i))))
    end
    return update, 5000
end

return update()

It never says it works, the result of relay:get(i) is always 0.

More investigation:

It works perfectly on sim with 4.4 plane and 4.5.x plane. However it doesn’t work on an orange cube.

Tried another orange cube, this is working. There is something wrong with my other orange cube, I will update my findings here.