Hello I am trying to connect to the S3 server and while I’m trying to get the connection state I can’t find any pre defined api that does that. I’m currently using boto3 with python for this. Anyone with any idea how to constantly get the connectivity state to show if it’s connected or disconnected to the S3? it’s for display.
There is no "state". All requests are REST API calls. Once an API call is finished, there is no on-going connection between the systems.
Think of it like sending an email -- once an email has been sent to a server, there is no 'state' between the sending machine and the email server. They have no need for a 'connection state'.
Related
I'm trying to build a simple REST API proxy server that receives HTTP requests and forwards them to a remote server.
I need to make it so it is not transparent which means if the client sends a request and the proxy does not have a response ready in its cache, it will not block the user and instead will return another immediate respond in some format, so that the response could be sent to the client later.
I am trying to use Flask in order to create the server but I don't understand how can I send a response back to the client and later update him with the correct response from the server.
My Idea was to use Flask and whenever I get some request I will initiate a new thread that will send this request to the remote server and when the thread finished it will send the response back to the client.
But What do I send to the client before initiating the thread? I thought of a Future object maybe that I will resolve in the thread, but I don't really know if that is the right way to go about this since I am new to python and server programming.
I would Appreciate if someone could point me in the right direction as to how to implement this proxy server.
Thank you!
So first of all, what I really want to achieve: I want to know when an IoT device has stopped working (i.e. lost connection, shut down, basically it's not longer talking to IoT Core). I can't seem to find an implementation for this on GCP.
I have a raspberry pi as my IoT device, I have configured it on IoT core and somewhere I read that since this is not implemented a way to solve it is to create a logging sink which activates a cloud function whenever there is a CONNECT/DISCONNECT log. This would serve my purpose and I have implemented this sink and cloud function to alert me.
I have been following this guide on connecting to MQTT. However, the way the explain it, they set it up such that whenever the expiration time on the JWT is exceeded, they disconnect the client and create a new one to re-new the JWT. This would make it such that I am going to be alerted of connection/disconnection whenever this client needs to be renewed. So I won't be able to differentiate of a real issue from renewals of the MQTT client.
In the same guide, I see that they mention MQTT long term or LTS, and they claim that this way you can set up the client once and communicate continuously through it for the supported time which it says its until 2030. This seems to be what I really want, but I have not been able to connect this way and they don't explain it other than saying the hostname should be mqtt.2030.ltsapis.goog and to use a primary and backup certificates which are different from the complete root CA from the first method.
I tried using basically the same process for setting up the client:
client = mqtt.Client(client_id=client_id)
# With Google Cloud IoT Core, the username field is ignored, and the
# password field is used to transmit a JWT to authorize the device.
client.username_pw_set(
username='unused',
password=create_jwt(project_id, private_key_file, algorithm))
# Enable SSL/TLS support.
client.tls_set(ca_certs=ca_certs, tls_version=ssl.PROTOCOL_TLSv1_2)
but changing the hostname and giving it the primary cert where I would give it the complete ca_certs, but it won't accept it and I am not sure how to do it otherwise with primary and backup certifications. I am looking at the documentation on tls_set, but I don't see where these would go or how they differ from the complete ca certs. I haven't seen any other examples outside of this guide.
I am hoping to be able to connect to this MQTT LTS so that I can maintain the connection without having to constantly renew the client.
The long term MQTT domain lets you use the LTS configuration for a long period of time, not the connection.
As you mention, for your use case the solution would be to activate and use device logs. One of the events is triggered when a device disconnects from IoT Core, and you can use that event to trigger an alert.
Keep in mind that the time limits for the connection are set for security purposes, and the client should renew the connection.
I'm using a service that sends me some data from user over webhooks. If there is any user interaction on this service, it hits my URL with HTTP request, with the data in POST/GET, and then expects text/json response to show back to the user. The response has to be in few seconds, otherwise the HTTP request times out and the service has no way of finding out what should be the response to the user.
The problem here is that now I'm not processing these data on my server with public IP, but I need to do it on my RPi, which keeps moving, which meains it has different IP every few hours, and mostly not public.
I'm sure I will still need to use the server with public IP to redirect these requests to my RPi, and I have few ideas, but I don't know what is reliable or if it even would work.
Let the API talk to my server and save the data. Then have the RPi constantly asking my server if there are any new data. Propably the dumbest idea - not ideal to use over metered connection, propably longer reply, and it will be harder to return the RPi's reply in the HTTP request made from API.
Having (Python) script running on my server, that will a) serve as socket server and RPi will connect to this socket, and b) have running SimpleHTTPRequestHandler to process requests from API and send them to the socket, the reply with RPi's reply. Propably easy way to keep connection between my server and RPi, allowing me to pass data in both directions.
Open SSH tunnel between the RPi and my server. This way, I could process the requests from service directly on my RPi. But how reliable is this solution? (Keeping it alive, opening the tunnel automatically, etc, propably question for superuser forum)
I'm thinking of going with choice 3 if it will be possible, but first I'd like to hear what you guys think. Is this a good and reliable idea? Or are there any better ways I don't know about? Or did anybody already faced this problem?
To sum it up:
Something sends HTTP request to public IP. I need to process this request (and reply to it) in Python script on device without public IP. I have a server with public IP that could be used as a bridge. I much don't care what will run on the server, if it will be able to redirect these requests.
Thanks
I have managed to built a simple client server application in Twisted that takes the data from the serial port and send it to the server. I want to know how i can add any kind of authentication for accessing the server. Right now anyone with the server IP can send data to the server. Any help would be highly appreciated .
I can redirect you to this question.
Basically, you need to implement a protocol client & server sides that parses username and password, validates them and keeps the connection open / routes it to a new address, or closes it.
Lower level approaches are also possible, but way more complicated.
Twisted has an SSL auth built in, if it is of any interest to you.
I am working on BLE using python library bluez. I created a GATT Server with Heart Rate Service (180d)and added 2a37 characteristics with notify method using Dbus API. It works fine, it sends notification properly after connection establish. But, if by any means, if bluetooth connection breaks from client, i don't get any callback on server. A method is available StopNotify which is called when ever client disable Notification.
Anyone know any such method which inform server about Disconnection ?