Simple lua function to catch a nil when checking json values

Simple lua function to catch a nil when checking json values

function IsInString(theString, theText)
    print("IsInString (theString: '" .. theString .. "', theText: '" .. theText .. "').");
    if (tonumber(string.find(theString, theText)) == nil) then
        print(" String Not Found.");
        return false;
    else
        -- check the pos if the string to confirm (not nil is not enough)
        if (tonumber(string.find(theString, theText)) > 1) then
            print(" String Found.");
            return true;
        else
            print(" String Not Found.");
            return false;
        end
    end
end

I was doing this when processing json data but kept getting nil in the second elseif (nil was not being caught higher up.

if (event.response == nil) then
            --code
        elseif (event.response == "") then
            -- code
 
        elseif (tonumber(string.find(event.response, "ok")) > 1) then
            if (string.find(event.response, "true") > 1) then
                -- code
 
            end
            ...

PiFace, Python and controlling basic circuits

Setting up the PiFace

Source Setup Script: http://pi.cs.man.ac.uk/download/install.txt

    sudo apt-get install -y python-dev python-gtk2-dev git
    pushd ~/
    git clone https://github.com/thomasmacpherson/piface.git
    pushd piface/python
    sudo python setup.py install
    popd
    sudo piface/scripts/spidev-setup
    popd

Quick Circuit Setup
piface01

piface02

Sample Python code to power my 5x 5v lights and 1 speaker.

    #!/usr/bin/python
    from time import sleep
    import piface.pfio as p
    p.init()
    # while True:

    # Front LED On
    p.digital_write(0,1)

    # Speaker Test
    p.digital_write(4,1)
    sleep(0.1)
    p.digital_write(4,0)

    for intloop in range(3):

    # Red Led Test
    p.digital_write(1,1)
    sleep(0.2)
    p.digital_write(1,0)

    # Yellow Led Test
    p.digital_write(2,1)
    sleep(0.2)
    p.digital_write(2,0)

    # Green Led Test
    p.digital_write(3,1)
    sleep(0.2)
    p.digital_write(3,0)
    sleep(0.1)

    #2 light Test

    p.digital_write(1,1)
    p.digital_write(3,1)
    sleep(1)
    p.digital_write(1,0)
    p.digital_write(3,0)
    sleep(0.1)

    #1 Ligth test

    p.digital_write(2,1)
    sleep(1)
    p.digital_write(2,0)
    sleep(0.1)

    # Speaker Test
    p.digital_write(4,1)
    sleep(0.1)
    p.digital_write(4,0)
    sleep(0.1)
    p.digital_write(4,1)
    sleep(0.1)
    p.digital_write(4,0)
    sleep(0.1)

    #Turn All On

    p.digital_write(1,1)
    p.digital_write(2,1)
    p.digital_write(3,1)
    sleep(2)
    p.digital_write(1,0)
    p.digital_write(2,0)
    p.digital_write(3,0)

    #Turn Front Led Off
    p.digital_write(0,0)