I have used it to establish a console connection to a Cisco AP in order to perform send the initial set of configurations within a python script and automate the process. I will only talk about using it on macOS as this is what I use. See: Configure a Cisco IOS-XE AP for an APoS Site Survey using Python.
Use a console cable to connect your computer to the console port of the equipment. In my case, I am using an AirConsole.
Time to Code!
You can also set a timeout of the connection. This is optional and I have set mine to 1sec.
You also notice that I am printing the name of the Serial connection by using the ser.name variable.
In order to send a command, you will have to use this code (in this case we are just sending a return character):
- The text to be sent needs to be encoded using utf-8
- The '\r' character has to be added to the command in order to simulate the user pressing on Enter (Note: '\n' didn't work for me when interacting with the Cisco AP)
- You will have to use the sleep function to wait for the command to be executed and send you the output back
- The text received will have to be decoded using utf-8
This set of code will have to be executed for every command that you want to send out. So I would recommend creating a function that will do all of this for you. Here is an example:
Example - Show AP Summary
- PySerial documentation: pyserial.readthedocs.io/en/latest/pyserial.html
- Use of PySerial to configure a Cisco AP for an APoS: www.semfionetworks.com/blog/configure-a-cisco-ios-xe-ap-for-an-apos-site-survey-using-python