On YouTube I found a mind blowing video of Alejandro Magnitopic who easily created a working Telegram Bot communicating with a Python application. This video is the base of the project I would like to present to you in this article and most of the source code is coming from Alejandro. The video you can find here: https://www.youtube.com/watch?v=q9YScw0YBB4. It gives you also the first steps of how creating a Telegram Bot. I do not want to describe it in detail here.
The first task was to get the request Python resources into Amesim to get a easy to use web communication. Therefore I go from my point of view the easiest way. I went to https://pypi.org/project/ and downloaded the sources. After the download I just copied the resource into my Simcenter Amesim Folder (C:\Amesim\v1600\Amesim\sys\python\win64\Lib) like you can see in the picture below. There are some more resources needed to get requests started. The complete list you can find it the header of my code in the attachment.
After I had all the resources to get the Python code running I started using the Simcenter Amesim Simulation Scripting routines to control my simulation project. The Simcenter Amesim simulation is very easy as it is just a spring mass damper system. Using the Simcenter Amesim Help it was very easy to create the code finding the correct references. The code allows me to set a parameter, run the simulation and get a variable for further post processing.
And that’s it! My Telegram Amesim Bot Python script is ready. There are just some stumbling blocks in the way you have to move to the side:
Now I just have to open my Simcenter Amesim Model and start the Python command interpreter and give following command:
If the script started without any error you can use your Telegram App to control your Simcenter Amesim model. The picture below shows the possible commands. You will also see some feedback in the Python command interpreter.
So I hope you will enjoy your new simulation possibilities using Telegram Bot and Simcenter Amesim with Python scripting!
Tried it and it does work nicely (not on VPN).
Being a Python novice, I only struggled to extract the packages properly, this is how it should look like.
Okay there's probably too many folders I left in there, but it does work.
Thanks for validating the code. I also faced the same issue that is not working under some circumstances like VPN connection.
Regarding the Python packages I am also a novice. For me it worked also only copying the “request” folder which is highlighted in the picture below. The other folders like .egg-info, tests and the other files are not necessary.
Maybe there is a Python expert in the forum who can explain it to us.