Here is the code for the watering all plants.
I have improved the reliability of the base code so it attempts to read the plant list several times (dealing with network glitches) and recoded the movement so it performs a serpent movement. (Meaning it moves more logical in my mind).
Whack this into an LUA code block and wrap it with mount tool before and dismount tool after.
Job done.
If you need more help or LUA code assistance, I can help you there too.
Matt
local wt=variable(“Watering Time (Seconds)”)
local st=os.time()*1000
local tries=9
local delay=20
local fail=1
local pts
local wateringHeight=0
while tries>0 do
tries=tries-1
pts=api({method=“GET”,url=“/api/points”})
if pts then
toast(“Plant list obtained”,“info”)
tries=0
fail=0
else
toast(“Error - Retrying”,“warn”)
wait(delay*1000)
end
end
if fail==1 then
toast(“Fatal Error - No plants”,“error”)
return
end
local pls={}
for _,v in pairs(pts)do
if v.pointer_type==“Plant” then
table.insert(pls,{n=v.name,x=v.x,y=v.y})
end
end
– Dynamic X clustering with serpentine Y sweep
local tol=50
table.sort(pls,function(a,b)return a.x<b.x end)
local grps={{}}
for _,p in ipairs(pls)do
local g=grps[#grps]
if #g==0 then
table.insert(g,p)
else
if math.abs(p.x-g[1].x)<=tol then
table.insert(g,p)
else
table.insert(grps,{p})
end
end
end
local s_pls={}
for i,g in ipairs(grps)do
table.sort(g,function(a,b)return a.y<b.y end)
if i%2==0 then
local rev={}
for j=#g,1,-1 do table.insert(rev,g[j])end
g=rev
end
for _,p in ipairs(g)do table.insert(s_pls,p)end
end
pls=s_pls
local c=0
local t=#pls
local job=“Watering “…t…” plants”
send_message(“info”,job…" for "…wt…“s each”,“toast”)
for _,v in pairs(pls)do
local cn=“(”…math.floor(v.x)…“,”…math.floor(v.y)…“)”
local pn=v.n or"plant"
if #pn>20 then pn=string.sub(pn,1,20)…"…"end
set_job_progress(job,{percent=100c/t,status="Moving to “…pn…” "…cn,time=st})
move_absolute(v.x,v.y,wateringHeight)
set_job_progress(job,{percent=100(c+0.5)/t,status="Watering "…pn,time=st})
write_pin(8,“digital”,1)
wait(wt*1000)
write_pin(8,“digital”,0)
c=c+1
end
set_job_progress(job,{percent=100,status=“Complete”,time=st})