Docs - Examples - ping
This example is an improvised ping
utility for ATEM switchers:
$ python3 ping.py -h
[Tue Nov 24 21:48:32 2020] PyATEMMax demo script: ping
usage: ping.py [-h] [-i INTERVAL] ip
positional arguments:
ip switcher IP address
optional arguments:
-h, --help show this help message and exit
-i INTERVAL, --interval INTERVAL
wait INTERVAL seconds between pings, default: 1.0
It tries to connect to the specified ip once a second and reports result. Also allows to specify the interval between pings
with the -i
parameter.
$ python3 ping.py 192.168.1.111
[Tue Nov 24 21:52:14 2020] PyATEMMax demo script: ping
[Tue Nov 24 21:52:14 2020] Pinging ATEM switcher at 192.168.1.111 every 1.0 seconds
[Tue Nov 24 21:52:14 2020] Switcher connected
[Tue Nov 24 21:52:15 2020] Switcher connected
[Tue Nov 24 21:52:16 2020] Switcher connected
...
$ python3 ping.py 192.168.1.222 -i 10
[Tue Nov 24 21:52:26 2020] PyATEMMax demo script: ping
[Tue Nov 24 21:52:26 2020] Pinging ATEM switcher at 192.168.1.222 every 10.0 seconds
[Tue Nov 24 21:52:26 2020] Switcher DISCONNECTED
[Tue Nov 24 21:52:36 2020] Switcher DISCONNECTED
[Tue Nov 24 21:52:47 2020] Switcher DISCONNECTED
...
Code walkthrough
Start with the usual initial steps (explained in Examples)
Start working with the switcher:
First, the ATEMMax
object is created:
Then, the script enters an infinite loop:
For each iteration, the script will:
- Ping the switcher using the provided ip address
- Wait for the handshake to finish.
- With the result of
waitForConnection
the script knows which message to print:
- Then, the connection to the switcher is closed:
- And the script sleeps for the speciried
interval