What I’m trying to do:
I have several IoT Devices with both controlling and monitoring features. I need to send the information from web browser to IoT device and vice versa in almost real time.
What I’ve tried and what’s not working:
Right now, I am able to communicate between my server and Web app using Server UPLINK authentication mode. Where I am able to access the server data using anvil.server.callsI(). But now
also need an interface to anvil.server running on my linux server to devices.
Can we still use anvil client key for connecting between Device and Server.
I need the real time data transfer between multiple devices and server ?
Store the data in the server data base and made it accessible to webapp via uplink interface. ?
Can we use single server key to connect with multiple devices or we need any other communication
between server and devices ?
Is it possible to implement websockets in anvil web app and to server ?
then it can use your app’s Client key to communicate to your Server, the same way a browser (running your App) can. All by itself, this would satisfy requirement 1.
Your server-side code would be responsible for satisfying requirement 2. That code has access to your database, and could provide Uplink-callable routines.
Support for option 3 is built into Anvil’s communication structure. But I would recommend using your Client key, instead, unless you absolutely need to use a Server key.
Regarding 4, I know folks have built REST services in Anvil, but I don’t know about websockets.
I have a project that does something very similar. For that, I use a crossbar server and I have a python script running that registers itself both with the crossbar router and with anvil.
The regular Anvil server is not persistent. Every time you make a server call, a new Python instance is spun up to handle the server call, and then goes away when the server call is done. (Business plan can ask for a server to be persistent, but that’s not a guarantee).
So it doesn’t really make sense to think about a websocket connection from client to server. You could probably manage one between an uplink and a client, since both are persistent.
As Owen says, using third-party messaging services seems to be how people accomplish what you want.
@p.colbert Thanks for detailed explanation. Now I am left with only one question.
In case of anvil server connected with multiple clients using Client Key, how to have separate connection channel for each server to client(1/2/3/N) session. I mean some kind of ID is required to distinguish between multiple clients in my case Devices running with python and connected to a single server.
With little of my understanding we can actually pass the custom function name with each client and store in data tables. By my data is continuous like every server to client session is like a separate chart instance like flooding of messages like Linux boot log etc.
Still can we use data tables for storing such a huge log ? I would like to maintain logger channel on server end and save the data coming for different devices in different text file on day basis ! Is that possible ?
The simplest approach is for each Device to pass its ID as a parameter in the call. The receiving end (server) then knows exactly where each call came from.
How you
assign the IDs, and
install one on each device
is up to you.
See Pricing, in the menu above, to get a sense of your data limits. If, after that, data volume is still an issue, you might look at ways to compress your data, either at the source or the destination.
Very possible. The database can store Media Objects, which are essentially binary files. I use them for storing zipfiles. When I need the data in uncompressed form, I use standard Python library routines, on the server, to extract and decompress selected contents from the zipfile.