Uplink, external DB, Data-path/Signals

Our situation is such that we have a Raspberry Pi with sensors ready to transmit data when an event occurs, lets call this appT for T)ransmit. Typically physically located only about 100 meters away we have a laptop or such computer with WiFi ready to update a graphical display. Lets call this appR for R)eceive. Minimum latency is critical .

I have been reading/searching docs/forum and have picked up pieces of information about the Uplink feature, but I remain unclear what data, and what signals are being sent from where to where in the best case, and what that best case would involve…

Background: Until now we have assumed that a USA regionally located MongoDB with Reactive (wait) command built into the PyMongo Library would offer near real-time response while also providing persistence. We have tested it between two Python Applications and it is just very fast (no polling silliness, appT causes a document to be inserted, appR gets a signal, and receives the record it is ‘waiting’ for - all Async considerations neatly hidden).

Note: Our first, and most clients are expected to be located in central USA. I’ve been researching Uplink, and have found considerations of security, but nothing I could understand about the actual physical flow of Data / Signals that would be involved using the Uplink feature to best advantage given the geographical situation.

We seem to have a typical delay of less than 200ms using the MongoDB - Atlas with the excellent and well documented Pymongo library. This service is located central USA. We transmit only some 400 bytes per event. We need long term persistence, but I am okay to assume that a sending data from central USA to London, waiting on trigger, and sending back, besides being obscenely inefficient will also be way too slow.

So is there a Uplink (or other Anvil solution) that might make more sense than using our planned external DB solution, and using this solution what signals and data are being sent between which physical locations to ultimately send Data (and Signals) from appT to appR?

Is it necessary that the Pymongo library using code must exist on the Anvil server? Conversely: the connection code cannot exist in the Client portion of the program (in the browser).

Some background info I just looked up, so this is not just a guess:

  1. If the connection library (pymongo) must exist in the Anvil Server (and if it is necessarily based in London) , then there are two 6,400km trips between the RaspPi and the Laptop (that are usually located < 100m apart). The speed of light in fibre optic cables is approximately 200,000 km/second. Then an absolute minimum delay of 0.064 sec. added to everything else if Anvil server is part of the data-path (from our location in central USA).
  2. Also: According to renowned computer scientist Van Jacobson, one of the inventors of the TCP/IP protocol stack, a user begins to notice latency delay at 400 ms.

So, unless I’m missing something, it will be necessary to use this Uplink feature.

Have I missed something?

Hi @gmkoller, welcome to the Forum!

The Uplink does go through the Anvil server - it makes a websocket connection to the Anvil server, which in turn has a websocket connection to the browser.

Both the uplink and the browser are connected to the Anvil server with a websocket, and you can update or read data from the server in real time. Whenever your uplink or client side script contacts the server, the server will be ready to immediately respond.

An uplink script can have functions that can be called from the server, so you can have real time communication between uplink and server in both directions.

But the client side code cannot have functions called or events triggered by server code. This means that keeping the browser updated in real time is impossible. The best you can do is good old silly polling, which I use often with a 2 second interval on a timer.

Thanks.

Actually, code wise, this is a small, but unfortunately critical little spot in our project. I would be excited to think I might be able to work on both sides of this project in Python!

Ian has communicated with me that:
_

  • As far as Websockets are concerned, you can absolutely use those directly in the client if you wish - you will need to write the JS yourself, but you can integrate with the Python layer very easily._

This is not a world and level I am anxious to work at, but one of the things I love about the Raspberry Pi world is that everything is amazingly well documented, and I’m looking this moment at an example on how a Pi can use Socket.io to communicate to the Browser here: Real-Time Interaction with Web Browsers.

No idea how, or even if this fits our use case yet.

I need time to get my head wrapped around this and see what I else I might find out there in the fascinating world of Pi!

You will need to write some JS, but you will do it only once. For example we have some JS code that calls a Python function when the user scrolls a window. Then all the code that manages the scrolling is written in Python.

Thanks.

See my technical response to Stefano…

Please understand that being very new to Anvil and trying to figure out this largely unfamiliar to me communications level inside an Anvil client seems a little intimidating just now.

Just a side thought: in the wonderful world of Drones, these days, all kinds of communications (including rt camera images) are finding their way back and forth on these clever, and economical little units (for example drone motor control). On the other-hand I just need occasional packets of a modest 400 bytes or so, but we need them in real-time.
It’s just bloody unfair! :slight_smile:

**Installing a parallel running application of the same machine would lead to a ‘logistical’ /distribution/support(download/install - multiple OS support) nightmare. But I glance at this occasionally, as there are communications protocols and all that allow greater than 100m direct image transmissions to any of most computers/cellphone- thus we would not need our little buddy the Pi and could reduce costs - but where THIS would fit with Anvil seems even more vague.

(forgive me this gadankengang - its just that I have had nobody remotely technical enough to think this through with yet, hope its at least interesting. It all comes down to : if one wants to use the Web to ‘distribute’ & run an application, one has to play by the rules of the Web. )