Hi all,
Appreciate any advice on resolving my issue detailed below. I am working on moving a tkinter based python GUI into anvil. The application is essentially a stopwatch that increments every 0.1 seconds (I am currently using the Timer component in anvil to do this). Also within each tick increment, temperature and pressure readings are pulled from a Raspberry Pi set up as a server through uplink.
In order to maintain accurate time in tkinter, my approach was to wait each tick of the stopwatch based on the desired interval less the processing time, which resulted in a mostly accurate stopwatch (i.e. for a stopwatch incrementing every 0.1 second the wait time before incrementing was 0.1 - processing time). As I mentioned earlier, I am using the Timer ability in Anvil to manage the tick rate of the stopwatch in the function below:
Where counter is the value of the stopwatch and counterInterval is 0.1,
def timerCounter_Tick(self, **event_args):
global counter, counterInterval
counter = float("{:.1f}".format(counter + counterInterval))
self.labelCounter.text = "{:.1f}".format(counter)
Now that the stopwatch is mostly accurate, I added a server call to return the value of Temperature and Pressure as measured on the Raspberry Pi. The new timer function is below:
Where the getValues() function returns an array [Value of Temperature, Value of Pressure],
def timerCounter_Tick(self, **event_args):
global counter, counterInterval
counter = float("{:.1f}".format(counter + counterInterval))
self.labelCounter.text = "{:.1f}".format(counter)
sValueLst = anvil.server.call_s('getValues')
self.valueTemperature.text = sValueLst[0]
self.valuePressure.text = sValueLst[1]
Now this is where I ran into issues running the app… The stopwatch, given the additional tasks and server calls, now increments much slower than every 0.1 seconds, losing accuracy. I am curious how I can account for both processing time and network response time within each tick of the Timer component to maintain an accurate 0.1 second increment? Has anyone built an accurate stopwatch in anvil? If I ping www.anvil.app I get a response time of about 95 ms… Does this mean an accurate 0.1 stopwatch would be almost entirely infeasible?
The timing of the stopwatch does not need to be exact. I would accept if the stopwatch lost no more than a second over a 30 second period of time.
I am very new to this and am curious if my issue is my approach or if the application is just unrealistic.
If you are curious to look at the whole app, here it is:
https://anvil.works/build#clone:TY2ZDLBENJQJKDQ5=DL7L2CEA6XJGRIRNSHGX6Y4F
To reproduce the error, hit Run then select the green Play button to begin the stopwatch (not sure though if because I am using an uplink server if the app will run for other users).