Is there a way to see if my Discord bot is offline with a pyhton script? I'm trying to make a script that detects if my bot goes offline and it will run it in my other server if my host has a maintenance.
Is there any way to detect this?
You could follow the flask approach using uptimerobot to ping your web app every so often but this is limited to alerts if downtime is more than 5 minutes.
You could look at getting a reliable host that doesn't go down as often or looking at getting a VPS with a host with a high uptime SLA. You can look at https://uptime.is/ for seeing how long downtime is acceptable for a host.
If you know how to create good API servers, create a socket.io server, connect to it using your bot. Then listen for the disconnect event on the server then you know when your bot goes down/restarts.
Related
I am making my home smart using esp32 and micropython. I have a Django project running on a server I have on my LAN and I want to send commands to my esp32 wirelessly through it. Maybe something like running a uvicorn server and a fastapi app and then sending messages to the uvicorn server endpoints and I have no idea how to do this.
You should probably use either Django Channels or django-websocket
But I'm not sure if websockets package is ported for micropython, so you might need to use plain socket
Or try something completely different. Physically connect the server and esp32 together (I have absolutely no idea about it)
My recommendation is the first option
I have been hosting a discord bot on my raspberry pi for half a year now, but after the new discord update my bot seems to go offline within two hours of closing out my PuTTy shell and vnc viewer which I use to access my raspberry pi. After testing different things when I try and restart the bot via vnc I get a Temporary Failure in name resolution which I learned only goes away if I rewrite my token in the script using PuTTY however this put me in a loop because 2 hours after closing out of the PuTTy shell the bot goes offline again and I have to repeat the process. I am still relatively new to all of this and would really like any kind of help.
edit: I just found out that I don't even need a new token to get rid of the error all I need to do is run it in PuTTy and close it immedietly when I do the same thing through the vnc viewer nothing happens and the error persists.
I'm creating a python flask api on remote desktop and running it on localhost of remote desktop.
Is there anyway I can access this api from my local machine?
We are working in a team and I want to share this with my team members, but this is confidential and not to be deployed on open server.
We want to post and get the result with every member's local machine from api runnnig on remote desktop.
Both of our local machines and remote desktop are windows10.
Sorry for being abstract but I'm searching for any way out. Thanks.
Well, you should open your way to this API. You'll have to set up a VPN or IP address filter in the server so you can access the server from your network while still have it secured on the Internet. You can also setup a simpler proxy if you prefer it. I'll not cover the details on how to setup a VPN or proxy since it can get pretty extensive, but a Google search will help you out find the best alternative for you.
AFAIK, the Remote Desktop Protocol does not allow for any kind of VPN. However, if you can switch to TeamViewer, it does have an easy to setup VPN system that will allow you to get into the network with few configuration. Once a VPN is configured, it will work like if you were in the same network as the server, so from there you can access your API from your host machine by just going to the IP address of the server.
Do notice the security policies of whoever owns the server, since you can get into trouble if you don't have permission to enable some access from the outside. Security goes always in front of comfort.
Short term solution:
Firstly download ngrok for your operating system.
For debugging and testing purposes you can expose a secure tunnel connection to your API by running this command in your command prompt / terminal.
ngrok http <PORT_NUMBER>-host-header="localhost:<PORT_NUMBER>"
Where PORT_NUMBER is the port number in which your flask application is running.
Example if your flask application is running at port 5000 then simply execute this command:
ngrok http 5000 -host-header="localhost:5000"
Running this will give you two hostnames one with HTTP and other a secure HTTPS connected by a tunnel like this for a duration of 8 hours after which the command needs to again re-run.
Which you can call remotely
Long term solution:
Deploy flask application using FastCGI
or
To a cloud infrastructure provider like Microsoft Azure which gives readymade templates for flask applications.
My requirement is to communicate socketio with nodejs server to Raspberry Pi running a local Python app. Please help me. I can find ways of communication with web app on google but is there any way to communicate with Python local app with above mentioned requirements.
It's unclear exactly which part you need help with. To make a socket.io connection work, you do the following:
Run a socket.io server on one of your two computers. Make sure it is listening on a known port (it can share a port with a web server if desired).
On the other computer, get a socket.io client library and use that to make a socket.io connection to the other computer.
Register message handlers on both computers for whatever custom messages you intend to send each way and write the code to process those incoming messages.
Write the code to send messages to the other computer at the appropriate time.
Socket.io client and server libraries exist for both node.js and python so you can either type of library for either type of system.
The important things to understand are that you must have a socket.io server up and running. The other endpoint then must connect to that server. Once the connection is up and running, you can then send message from either end to the other end.
For example, you could set up a socket.io server on node.js. Then, use a socket.io client library for python to make a socket.io connection to the node.js server. Then, once the connection is up and running, you are free to send messages from either end to the other and, if you have, message handlers listening for those specific messages, they will be received by the other end.
I am trying to setup Pusher to send messages from server to server. I do not need a client setup. I am trying to make the one server aware the other server is finished doing a particular task. Can anyone help with this?
Thanks
I work for Pusher. Have you tried using our server libraries? Some platforms have both a client (subscription) and server (publishing) library so you should be able to do what you want.