GoPro Script - Hero5 Session
-
- Posts: 16
- Joined: Sun Apr 16, 2017 12:11 pm
I have the gopro start/stop scripting working. I would really like to leave the camera off with wifi enabled and have the racecapture wake it up to start recording.jeffmcaffer wrote:I got something working for WoL and the GP Session. Here is the rough outline.
After joining the camera's network you tell the camera to wake up using
I am trying to get the wake on lan to work on a Hero 4.
My problem is when the camera is asleep, I can't connect to the cameras network.
If i let the race capture connect to the camera, power the camera off and wait for a delayed magic packet transmission, the camera will wake up. So I know my wake on lan function and mac address, etc. is correct.
The error i get when trying to connect to the sleeping camera.
CW_JAP:3 which according the ESP8266 documentation is "cannot find the target AP"
I really think this should work, I can do essentially what I am trying with a cell phone or a pc. Connect to the sleeping cameras wifi, use a WOL app to send a wake on lan packet and it wakes right up. Is there a different way to connect to the camera?
Any ideas would be appreciated.
Dennis
Code: Select all
count = 0
--Specify your GoPro wifi password here
goproPwd = 'florida96'
--Specify your GoPro SSID here
goproSsid = 'gpro'
--Specify Mac address of GoPro for WOL
mac ='D4D919C8F602'
--Speed threshold to start recording
goproStart = 50
--Speed threshold to stop recording
goproStop = 20
--How fast we check, in Hz
tickRate = 10
--Set this to 1 to log communications between RCP & WiFi
debug = 1
-----------------------------
--DO NOT EDIT BELOW
-----------------------------
--the serial port where the WiFi is connected
port = 4
--indicates wifiStatus
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready
wifiStatus = 0
lastInitTime = 0
initTimeout = 20000
function logMsg(msg)
println('[GoProWiFi] ' ..msg)
end
function sendCrlf()
writeCSer(port, 13)
writeCSer(port, 10)
end
function sendRaw(val)
for i=1, #val do
local c = string.sub(val, i, i)
writeCSer(port, string.byte(c))
end
end
function sendAt(val)
if debug == 1 then logMsg('send: ' ..val) end
sendRaw(val)
sendCrlf()
end
function toInt(val)
return string.sub(val, 1, -3)
end
function httpGet(url)
sendAt('AT+CIPSTART="TCP","10.5.5.9",80')
sleep(500)
local crlf = string.char(13) ..string.char(10)
local get = 'GET ' ..url ..' HTTP/1.0' ..crlf ..crlf
sendAt('AT+CIPSEND=' ..toInt(#get))
sleep(100)
sendRaw(get)
sleep(100)
sendAt("AT+CIPCLOSE")end
function sendGoProShutter(cmd)
httpGet('/bacpac/SH?t=' ..goproPwd ..'&p=%' ..cmd)
end
function startGoPro()
logMsg('start GoPro')
sendGoProShutter('01')
end
function stopGoPro()
logMsg('stop GoPro')
sendGoProShutter('00')
end
recording = 0
function initWiFi()
logMsg('initializing')
sendAt('AT+RST')
sleep(2000)
sendAt('AT+CWMODE_CUR=1')
sleep(1000)
sendAt('AT+CWJAP_CUR="' ..goproSsid ..'","' ..goproPwd ..'"')
wifiStatus = 1
end
function processIncoming()
local line = readSer(port, 100)
if line ~= '' and debug == 1 then print('incoming response: ' ..line) end
if string.match(line, 'WIFI GOT IP') then
wifiStatus = 2
end
if wifiStatus == 2 and string.match(line, 'OK') then
wifiStatus = 3
logMsg('ready for GoPro')
end
end
function checkGoPro()
if wifiStatus == 0 then
initWiFi()
lastInitTime = getUptime()
return
end
if wifiStatus == 1 and getUptime() > lastInitTime + initTimeout then
logMsg('could not connect to GoPro')
end
processIncoming()
if wifiStatus ~= 3 then
return
end
trigger = getAnalog(1)
if recording == 0 and trigger > goproStart then
startGoPro()
recording = 1
end
if recording == 1 and trigger < goproStop then
stopGoPro()
recording = 0
end
end
function wakeGoPro()
logMsg('waking GoPro')
local macChars = ''
for w in string.gmatch(mac, "[0-9A-Za-z][0-9A-Za-z]") do
macChars = macChars .. string.char(tonumber(w, 16))
end
local magicPacket = string.char(0xff):rep(6) .. macChars:rep(16);
logMsg('Waking GoPro')
sendAt('AT+CIPSTART="UDP","10.5.5.9",9')
sleep(500)
sendAt('AT+CIPSEND=' ..toInt(#magicPacket))
sleep(100)
sendRaw(magicPacket)
sleep(100)
sendAt("AT+CIPCLOSE")
sleep(2000)
end
function onTick()
if wifiStatus == 0 then
initWiFi()
end
processIncoming()
if count == 200 then
wakeGoPro()
end
count = count +1
end
setTickRate(tickRate)