Hi Klaus
Sorry I just realized it would be better to post the whole page script-
(the request tide command returns for example -
https://www.worldtides.info/api?datum=L ... 996f0645d4)
Thanks v much
local tlat
local tlon
local ttidal_request
local tlowtidelevel
local tlowtidetime
local tlowtidetime1
local tepochtide
local tmylat
local tmylong
global tDatabaseID
local station_id
local t_tidetime
constant WT_Key = "1449737d-0844-46a7-a344-9d996f0645d4"
on opencard
put empty into field "arraydata"
put empty into field "arrayspecifics"
databaseConnect
answer question "Please confirm that you have a wifi or 3G connection before continuing " with "Yes" or "No"
if it is "no" then
answer "please wait untill you have a signal, then log back into the app"
exit to top
else
checkInternetConnection
read_epochtime
read_latandlong
request_tide
json
json2
databaseInsert_tidelevel
databaseInsert_tidetime
end if
end opencard
command request_tide
put tmylat into tlat
put tmylong into tlon
put "
https://www.worldtides.info/api?datum=Lat&extremes&lat=" & tlat & "&lon=" & tlon & "start=" & tepochtide & "&length=86400&maxcalls=5&key=" & WT_Key into ttidal_request
answer ttidal_request
end request_tide
command json
put URL (ttidal_request) into ttidal_response
#put URL "
https://www.worldtides.info/api?datum=L ... 996f0645d4" into ttidal_response
if ttidal_response is not empty then
answer "api seems to contain response"
end if
put jsonimport(ttidal_response) into tArray
combine tArray by return and tab
put tArray into field "arraydata"
end json
command json2
#put empty into the field "arrayspecifics"
put URL ttidal_request into ttidal_response
put jsonimport(ttidal_response) into tArray
put tArray[station] into station_id
put tArray[extremes] into tSubArray1
put tSubArray1[1] into tSubArray2
put tSubArray2["type"] into tlowtide
put tSubArray2["height"] into tlowtidelevel
put tSubArray2["date"] into tlowtidetime
if tlowtide is "Low" then
put tlowtidetime into t_time
set itemdel to "T"
put item 2 of t_time into tlowtidetime1
set itemdel to "+"
delete item 2 of tlowtidetime1
put "low tide-" & tlowtidelevel & "m," && "low tide time-" & tlowtidetime1 &"(UTC)," && "tidal station-" & station_id into the field "arrayspecifics"
else
put tSubArray1[2] into tSubArray2
put tSubArray2["type"] into tlowtide
put tSubArray2["height"] into tlowtidelevel
put tSubArray2["date"] into tlowtidetime
if tlowtide is "Low" then
put tlowtidetime into t_time
set itemdel to "T"
put item 2 of t_time into tlowtidetime1
set itemdel to "+"
delete item 2 of tlowtidetime1
put "low tide-" & tlowtidelevel & "m," && "low tide time-" & tlowtidetime1 &"(UTC)," && "tidal station-" & station_id into the field "arrayspecifics"
else
put tSubArray1[3] into tSubArray2
put tSubArray2["type"] into tlowtide
put tSubArray2["height"] into tlowtidelevel
put tSubArray2["date"] into tlowtidetime
if tlowtide is "Low" then
put tlowtidetime into t_time
set itemdel to "T"
put item 2 of t_time into tlowtidetime1
set itemdel to "+"
delete item 2 of tlowtidetime1
put "low tide-" & tlowtidelevel & "m," && "low tide time-" & tlowtidetime1 &"(UTC)," && "tidal station-" & station_id into the field "arrayspecifics"
else
put tSubArray1[4] into tSubArray2
put tSubArray2["type"] into tlowtide
put tSubArray2["height"] into tlowtidelevel
put tSubArray2["date"] into tlowtidetime
if tlowtide is "Low" then
put tlowtidetime into t_time
set itemdel to "T"
put item 2 of t_time into tlowtidetime1
set itemdel to "+"
delete item 2 of tlowtidetime1
put "low tide-" & tlowtidelevel & "m," && "low tide time-" & tlowtidetime1 &"(UTC)," && "tidal station-" & station_id into the field "arrayspecifics"
else
put "can't determine low tide " into the field "arrayspecifics"
end if
end if
end if
end if
#put tSubArray3 into tsub
#combine tSubArray2 by return and tab
#put tSubArray3 into field "arrayspecifics"
#put tsub into field "arrayspecifics"
#combine tArray by return and tab
#put tArray into field "arraydata"
#put tArray[responseDatum] into field "arrayspecifics"
#put tArray[extremes] [dt] into field "arrayspecifics"
#put depthvariable into field "arrayspecifics"
end json2
command checkInternetConnection
put url "
http://www.google.com" into tURL
if tURL is empty then
answer "no internet connection found, please try again later"
else
answer "testing internet connection........connection established"
end if
end checkInternetConnection
command read_epochtime
set the defaultFolder to specialFolderPath("documents")
put URL ("file:epochofsurvey.txt") into tepochtide
end read_epochtime
command read_latandlong
set the defaultFolder to specialFolderPath("documents")
put URL ("file:currentlat.txt") into tmylat
put URL ("file:currentlong.txt") into tmylong
end read_latandlong
command databaseConnect
if tDatabaseID is a number then
answer "the database connection was successful, your connection id is" && tDatabaseID
else
answer "Unable to connect to the database, no existing connection"
end if
end databaseConnect
on databaseInsert_tidelevel
put tlowtidelevel && "(LAT from tide station;" && station_id &")" into t_tidelevel
put "UPDATE survey_details SET lowtide_level = :1 WHERE rowid =1" into tSQL
revExecuteSQL tDatabaseID, tSQL, "t_tidelevel"
end databaseInsert_tidelevel
on databaseInsert_tidetime
put tlowtidetime1 && "(UTC from tide station;" && station_id &")" into t_tidetime
put "UPDATE survey_details SET lowtide_time = :1 WHERE rowid =1" into tSQL
revExecuteSQL tDatabaseID, tSQL, "t_tidetime"
end databaseInsert_tidetime
command test_save
set the defaultFolder to specialFolderPath("documents")
put t_tidetime into URL ("file:tide_test.txt")
end test_save