Home        Store        Docs        Blog

Run a python script on companion

can i run a new python script on companion computer (Rpi which is loaded with ardusub O.S) for a sensor data reading?

Did you find the answer you were looking for? I am also looking for this.


Yes, it’s possible!
You can access companion via a SSH terminal, or a file manager that access companion via a ssh connection.
You can check more here: https://www.ardusub.com/operators-manual/companion-web.html

Hello Patrick,
I also have a problem with running a python script on the companion side.

May I know if there is any possible way to run a python script once the companion side is ready (without a topside computer)?

I have tried to run the python script as a startup service (some Linux setting) but the script can only be executed after I connect the topside computer. The script executes after the Ethernet of companion side is ready, it is normal for an ROV when the top side computer is required but now I want to write some script for an AUV.

Thanks for helping!


Yes, it’s totally possible, companion is a computer as any other, it’ll work with our without ethernet connection.

Please share your script and how did you configure companion to do such thing.

I would recommend to set a cron job if you want to run a program on the startup.

  1. Open the terminal via ssh or using the web terminal.

  2. Create a folder called my_program

    mkdir my_program
    cd my_program
  3. Create a simple python program in the same directory

     #!/usr/bin/env python
     from datetime import datetime
     import time
     # Create a file to write
     while True:
         with open('/tmp/my_output.txt', 'a') as file:
             # Get current time and print with our format
             now = datetime.now()
             current_time = now.strftime("%H:%M:%S")
             file.write("Time = {}\n".format(current_time))
         # Sleep for 2 seconds and repeat

    The program will write the actual time in a file called /tmp/my_output.txt, and it’ll repeat after 2 second.

  4. Make your program executable

    chmod +x my_program.py
  5. get the full path of your program.

    readlink -f my_program.py
    # it should output: /home/pi/my_folder/my_program.py
  6. Open the crontab editor

    contrab -e
  7. Add your program with the reboot command in the end of the contrab editor

    @reboot /home/pi/my_folder/my_program.py

    The @reboot command will schedule your program to execute during the system boot

  8. Save and close the contrab editor

  9. Reboot your system

    sudo reboot
  10. Check the output of the file

    cat /tmp/my_output.txt
    Time = 14:44:11                                                                                                                                                                       
    Time = 14:44:13                                                                                                                                                                       
    Time = 14:44:15                                                                                                                                                                       
    Time = 14:44:17                                                                                                                                                                       
    Time = 14:44:19                                                                                                                                                                       
    Time = 14:44:21                                                                                                                                                                       
    Time = 14:44:23                                                                                                                                                                       
    Time = 14:44:36                                                                                                                                                                       
    Time = 14:44:38
    Time = 14:44:40

As you can see, the file is being filled by our program after the reboot.