Skip to content

Best practise for reacting to a transfered file #22380

Discussion options

You must be logged in to vote

That code is blocking, meaning that you cannot do anything (including transferring files) while it runs. It will not wait 100 ms between checks, but it will schedule a shitload of those timers, which does not exactly help the situation.

Something like this works better, doing the check inside the periodic checking function

def poller(max, found)
  import path
  if path.exists('Door.png')
    found()
  elif max
    print(f'Waiting...{max}')
    tasmota.set_timer(100,/->poller(max-1, found))
  else
    raise 'error','failed to receive file'
  end
end
poller(120, /->print('got it'))

Also illustrates how to proceed with further code when the file is found, and a sanity check to prevent infin…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@waltkind
Comment options

Answer selected by waltkind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants