Python & Flask Push Messages - rest

I am developing a sort of IoT type system, where there is control software, a server, and client devices (which are embedded linux devices).
I have a flask server running a REST web service. Control software sends messages for a specific device to the flask web service running on the server. When these messages are received, they are stored in a database.
Client devices poll the sever to determine if there is a new message waiting for the device. This works well but becomes prohibitive as the number of devices grows.
I'd like to find a way to have the messages sent directly from the server to the device as they are received at the server. Is there a simple way to add this functionality to flask? This seems a bit like push notifications.
Is it possible to have each device open a socket like communication to the server and keep it open? Is this a bad idea if I just use TCP sockets for this?

Related

How to write an online socket server for a gsm based project?

I am developing a project about gps. I am trying to read the location from satellite and want to send them a server by using sockets. My module 'a9g' can read the location and send the things to a server.I have a domain and hosting. Now, I am trying to write a socket server which listens and accepts socket requests and can receive and transmit data. After, I will deploy it to the internet. I tried to do it in asp.net core websockets but my device can't connect to server that I wrote. I can't figure out which programming language should I use and how can I write and deploy a server. (My hosting is windows server.) I will add some photos of my microcontroller's functions and an example server.
Functions:
Socket Functions of microcontroller 1
Socket Functions of microcontroller 2
Socket Functions of microcontroller 3
There is an example server of ai-thinker: http://tt.ai-thinker.com:8000/ttcloud
I need exactly something like that. I have to accept many clients(my modules) and data exchanges between server and them. Could you help me how can I do that?
Additional notes:
1. I can connect the ai-thinker's example server. Send, read data from there.
2. I need to deploy it to my hosting server, so it should work on internet not only locally.

How to setup server for SMS communication for Teltonika FMB920

I am tring to create a vehicle tracking system based on GPS & GMS using Teltonika FMB920 tracking device. I am a bit confused on following things:
How to setup the server for communicating with the device.
How to save the data sent from the device on the server.
Can I use any cloud platform like Azure or AWS IoT features for this purpose.
Any guidance in this regard will be really helpful for me.
How to setup the server for communicating with the device.
Teltonika fmbxxx typically send data using websockets TCP or UDP protocol. To setup the server correctly, the port that will be listening for data needs to be opened in the server and the server address and port need to be configured on the device with the teltonika configurator tool
how to update server settings in configurator tool
How to save the data sent from the device on the server.
This depends on your use case but a good idea could be to use nosql database to save the data from device received by the server since its easier to scale when data size grows and easy to query and read the data
Can I use any cloud platform like Azure or AWS IoT features for this purpose.
AFAIK yes you can. essentially what is need is server instance with a websocket client application that can receive data from tcp/udp protocol

How to execute specific services on each iot device connecting on a tcp server?

I have 100K of iot devices connecting on tcp server. I have to select specific services to be executed on each device based on the device id. Right now I am using a rest api, that I call upon when a device connects to the server,which in turn returns the list of services to be executed on the device, these services on each device are selected by users using a web portal, my problem is when all these devices connects at the same time, rest api server goes down or hangs or takes time to serve the request, my need is to get the response back in milliseconds please suggest any better solution that can server my purpose.

What are options for finding a socket connection and then push data when your connections are spread across multiple hosts

I'm trying to build a web app that operates in real-time via a push model. I've used sockets in the past to achieve this, just not in a distributed service. My question is: Given that the host that receives the updated information (via Amazon
SQS) is not necessarily the host that the necessarily the host that
the web browser has a socket connection open with, How do we find the socket connection and then push the data.
Thanks

How to deploy a WebSocket server?

When deploying a web application running on a traditional web server, you usually restart the web server after the code updates. Due to the nature of HTTP, this is not a problem for the users. On the next request they will get the latest updates.
But what about a WebSocket server? If I restart or kill the old process all connected users will get disconnected. So my question is, what kind of strategy have you used to deploy a WebSocket server smoothly?
You're right, every connected user will be disconnected if the server restarts.
I think the less bad solution is to tell to the client to reconnect in the onClose method of the client.
WebSockets is just a transport mechanism. Libraries like socket.io exist to build on that transport -- and provide heartbeats, browser fallbacks, graceful reconnects and handle other edge-cases found in real-time applications.
In our WebSocket-enabled application, socket.io is central to ensuring our continuous deployment setup doesn't break users' active socket connections.
If clients are connected directly to sever that does all sockets networking and application logic, then yes - they will be disconnected, due to TCP layer that holds connection.
If you have gateway that clients will be connecting to, and that gateway application is running on another server, but will communicate and forward messages to logical server, then logical server will send them back and gateway will send back to client responses. With such infrastructure, you have to implement stacking of packets on gateway until it will re-establish connection with logical server. Logical server might notify gateway server before restart. That way client will have connection, it will just wont receive any responses.
Or you can implement on client side reconnection.
With HTTP, every time you navigate away, browser actually is creating socket connection to server, transmits all data and closes it (in most cases). And then all website data is local, until you navigate away.
With WebSockets it is continuous connection, and there is no reconnection on requests. Thats why you have to implement simple mechanics when WebSockets getting closing event, you will try to reconnect periodically on client side.
It is more based on your specific needs.