mqtt.lua – for camera | flash relase BRKR = "aaa.bbb.ccc.zzz" -- 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 = "2_LED" -- The MQTT ID. Change to something you like TPIC = "fire" -- MQTT topic to subscribe gpio.mode(3, gpio.OUTPUT) -- GPIO0 shutter open gpio.mode(4, gpio.OUTPUT) -- GPIO2 flash fire gpio.write(3, gpio.HIGH) gpio.write(4, gpio.HIGH) tmr.alarm(0, 5000, 1, con_broker) -- mS time function con_broker() -- connect to the MQTT 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() m:subscribe(TPIC , 0, function(conn) print('TPIC:',TPIC) end) tmr.stop(0) main() end function main() -- main program print('MAIN:','PROG') m:on("message", function(conn, TPIC, data) -- Callback to receive the subscribed topic messages if data == "4_LED" then -- 4_LED client (other camera|flash relase) data = nil elseif data == "2_LED" then -- this client data = nil end if (data ~= nil) then print('TPIC:',TPIC,data) if (data ~= CLID) then m:publish(TPIC,CLID,0,0, function(conn) end) if data=="flash" then gpio.write(3, gpio.LOW) -- shutter open tmr.delay(126000) -- min/max uS delay for 1/250s gpio.write(4, gpio.LOW) -- flash fire start tmr.delay(25000) gpio.write(3, gpio.HIGH) -- shutter close gpio.write(4, gpio.HIGH) -- flash fire stop end end end end) end Pages:Previous 1 2 3 4 5 6 7 8Next