mqtt.lua is main operation script – links with MQTT broker. Depends on electronic client construction – reads button or relase camera shutter | fire flash.

Again, remember to change IP for client (aaa.bbb.ccc.yyy) according to your network settings!

 mqtt.lua – for switch button MQTT client 
BRKR = "aaa.bbb.ccc.yyy"   -- IP/hostname of MQTT broker (Raspberry Pi)
PORT = 1883                -- MQTT broker port
USER = "youruser"          -- If MQTT authenitcation is used then define the user
PSWD = "yourpswd"          -- The above user password
CLID = "1_LED"             -- The MQTT ID. Change to something you like

TPIC = "fire"              -- MQTT topic to subscribe

gpio.mode(4, gpio.INT)     -- GPIO2 switch button
gpio.trig(4, "down",debounce)

gpio.mode(3, gpio.OUTPUT)  -- GPIO0 feedback LED
gpio.write(3, gpio.HIGH)

tmr.alarm(0, 5000, 1, con_broker) -- mS timer

function con_broker()      -- connect to the broker
    print('WAIT:','MQTT BRKR')
    m = mqtt.Client( CLID, 0, USER, PSWD)
    m:connect(BRKR , PORT, 0, function(conn)
        print('BRKR:',BRKR)
        print('PORT:',PORT)
        print('CLID:',CLID)
        sub_mqtt() --run the subscription function
    end)
end

function sub_mqtt() -- subscribe topic
    m:subscribe(TPIC , 0, function(conn)
        print('TPIC:',TPIC)
    end)
    tmr.stop(0)
    main()
end

function pub_flash() -- flash pulse
    m:publish(TPIC,"flash",0,0, function(conn)
        if (data ~= nil ) then
            print('DATA:',CLID,data)
        end
    end)
end

function debounce() -- switch debounce
    tmr.delay(25000)
    if gpio.read(4) == 0 then
        pub_flash()
    end
end

function main() -- main program
    print('MAIN:','PROG')
    m:on("message", function(conn, TPIC, data) -- feedback
        if (data ~= nil ) then
            print('TPIC:',TPIC,data)
            gpio.write(3, gpio.LOW)
            tmr.delay(25000) -- uS delay
            gpio.write(3, gpio.HIGH)
        end
    end)
end