I set a scheduled task every 1 minute.
It seems to work, but how do I call my Pico in this function?
The Pico function that I want to call is 'message" and takes 3 parameters.
normally when I call it from the client side I write:
anvil.server.call(‘message’, nr, l1, l2)
but I tried the 2:
see the line “anvil.server.call(‘message’, nr, l1, l2)” in my code, that’s my question.
The rest is executed from the scheduled task, but not the pico call.
if I try it with a timer on the client side, it works fine and calls the Pico (sends the message)
Maybe I need to put the UPLINK code inside this function, I don’t know.
msgbool = msgboolcheck()
notsendnrs = [r['msgnr'] for r in app_tables.msg.search(msgsend=False)]
if len(notsendnrs)> 0:
nr1stnotsend = notsendnrs
rowid = app_tables.msg.get(msgnr=nr1stnotsend)
nr = rowid['msgnr']
l1 = rowid['msgl1']
l2 = rowid['msgl2']
anvil.server.call(‘message’, nr, l1, l2) is the correct way. As long as the
message function in the Pico has been decorated with
@anvil.pico.callable_async, it is then available to both the frontend and backend of the Anvil app. Should you have errors, it is likely to come from your Pico loosing the websocket connection with Anvil and you can see this in the logs.
Thanks I will try again, but my Pico didn’t loose any connection and is working fine if I launch the same function with a timer. In the background tasks I saw that it succeeded with success, but still the Pico didn’t received any message. I have to check and try again. I will let it know.
Oh, I didn’t grasp that you were calling the Pico function from a background task. I don’t think it’d work for reasons stated here.
A workaround could be to wrap the call to the Pico function in a normal backend function, and then call this backend function in the background task. I’ve not tested this before so your mileage may vary. Good luck
I read the limitation in those docs a little differently: they apply when the background task is in the Uplink program, not when the Uplink program is called from a (server-side) background task.
Thank you for this answer. I will investigate further, but I am sure you are right, that this is the limitation that stops me to be able to use background task. Maybe a tip for Anvil, to solve this.