Lag between microscope and OpenFlexure Connect

Hello,

I currently connect the Raspberry Pi through Wi-Fi and connect to the microscope either through OpenFlexure Connect or straight from Firefox on the same computer or a tablet.

Sometimes I have absolutely no lag between my movements on the microscope and the image I see on screen but sometimes there is a lag that can be 3-5 seconds long.

What causes the lag and how can I improve it?

Thank you very much

The lag is mostly delay in the network traffic. Setting up the microscope on its own network infrastructure should help to avoid other traffic getting in the way. If you are using a computer near the microscope, the simplest way is to connect using a cable rather than WiFi - you may need a USB ethernet adapter. You can also set up the Pi as a WiFi host instead of connecting it as a client on your main network and then you can connect your computer to that hotspot. This is covered in Using rasp-ap to turn OFM into an access point - General - OpenFlexure Forum.
Both of these mean your Pi is not actually connected to the internet , so for updates etc you would need to re-connect to your main network.

Thank you for the input.
I forgot to mention that I set up my computer as a mobile hotspot. Does this count as own network infrastructure?

I think that I would expect that to be the same as the Pi being the access point. There might be extra things happening if your computer is also connected to a main network and sharing the connection over the hotspot.
Is the Pi also running a desktop? Which Pi version are you using?